0

I understand that, to get a list of clusters with pg_lscluster I need to use tools like pg_createcluster.

But, I use initdb and pg_ctl to create clusters. I know they are running because I can access each cluster (I have three clusters) with psql -p [port].

How do I get a list of clusters built with these tools?

2
  • 2
    pg_lsclusters searches the directories under /etc/postgresql to find the configuration of the clusters there. If you don't have your cluster configuration there, pg_lsclusters won't find the cluster. Commented Sep 22, 2023 at 8:53
  • Right. I was away of that. Which is why I am asking about initdb, not pg_lsclusters. Commented Sep 22, 2023 at 10:51

2 Answers 2

2

If you've created clusters using initdb and manage them with pg_ctl, they wont appear in the output of pg_lsclusters because pg_lsclusters specifically looks for clusters managed by the pg_createcluster tool.

You can still find info about the clusters you've created using initdb and pg_ctl by looking in the PostgreSQL data directory and configs.

Within the path to your PostgreSQL data directory there are subdirectories named after the PostgreSQL version and cluster names.

Within each data directory, there's a postgresql.conf files.

cat /var/lib/postgresql/<PostgreSQLversion>/<cluster_name>/postgresql.conf | grep "cluster_name"

Will show all the info about the cluster

2
  • Got it. Interestingly the cluster names and the ports of the clusters I created are commented out. And have the default port in the comment. I am a bit confused how my clusters work when the configs are commented like this. Commented Sep 22, 2023 at 10:50
  • 1
    Commenting out those lines simply means that the default values are being used. PostgreSQL will still function correctly because it has sensible default configurations that it can rely on if specific settings are not provided in the configuration file. Commented Sep 22, 2023 at 13:57
0

initdb or pg_ctl do not maintain any system-wise list. The cluster directory can be created (or subsequently moved) to a completely arbitrary location at the discretion of the administrator. Configuration files can also be anywhere. These utilities simply do what they are told to do.

Search for them as usual for unknown server:

  • check in the server documentation what to look for where
  • ask other administrators on the team
  • look at the list of processes and listening ports to see which network services are running. Connect to postgresql and check where it is located using show data_directory;

pg_createcluster (and pg_lscluster, pg_ctlcluster) are Ubuntu/Debian-specific wrappers around initdb and pg_ctl precisely for the purpose of providing a simpler interface for managing multiple postgresql instances on the same host. For example, a list of clusters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.