Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I seem to have a few installations of postgresql on my machine somehow. I'm not sure if this is a mistake or, if Ubuntu for some odd reason duplicates direcotories and keeps them elsewhere. I have a postgresql directory in /etc

one in /usr/lib

and one in /opt

I'm properly confused at this point. How do I go about deleting the extra ones.which ones are he extra one? I also need to make sure that my 'pg' gem in my rails env is pointing towards the correct posgresql db server.
Any thoughts on my issue would be huge.

share|improve this question
2  
Please avoid using unnecessary tags. –  zsquare May 30 '12 at 7:36
add comment

migrated from stackoverflow.com May 31 '12 at 8:38

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 3 down vote accepted

There can be some confusion over what people mean by an instillation. The /etc/postgresql/ folder is the config folder for your clusters. The /var/lib/postgresql/ folder is for data. The individual binaries for each version are in separate folders usually in /usr/lib/postgresql/ I really don't know about /opt/postgresql. I don't have that on mine, but /opt is for "optional" binaries, so it's possible that your installation is here instead of/usr/lib/postgresql/.

In short, I think you may just have one instalation which has files in multiple locations.

If you want to look at what you have installed, this may help:

How postgresql is structured:

To make things a little clearer postgres is structured as follows:

  • A version literally refers to which version of the postgresql binaries you have installed. Each version which is installed may have a cluster installed under that version. If not then that version is effectivly dormant as it has no data or running server associated.

  • Under each version there many be a number of clusters. You can think of the cluster as a running prostgres server (process). Each cluster has to have its own port/socket file for clients to connect to. Each cluster will be managed by a single version.

  • Inside each cluster will be a number of databases. When a client connects it selects a DB to connect to. It can ask to change which DB it's connected to without opening a new session, but it can only ever be connected to one.

What have you got installed?

To find out which versions are installed you can look to dpkg and apt. You should be able to unstall versions using apt and dpkg, but be very careful not to do this before you've checked what clusters are under each version.

To find out what clusters you have use the command pg_lsclusters. When I call this I get the following, you will get something different:

Version Cluster   Port Status Owner    Data directory                     Log file
9.1     main      5432 online <unknown> /srv/postgres/data/9.1/main        /var/log/postgresql/postgresql-9.1-main.log

Pay careful attention to the "Status" column. If a cluster is not online then it's just data on disk and is doing nothing. If it is online then it is running.

How do you merge clusters?

You can copy the content from one cluster to another using the pg_dumpall command to generate a backup and use psql to import it to the cluster you want to keep. Its worth keeping backups of everything before you start.

How do you remove a cluster that is no-longer used?

  • Use pg_lsclustes to get the details of the cluster and note the data directory and log file.

  • Use pg_ctlcluster <version> <cluster> stop to stop the cluster.

  • Remove the data folder and optionally the log file.

  • Finally remove the config for the cluster: All clusters will have their own config folder in
    /etc/postgresql/<version>/<cluser>/. The data folder will

Why did you get multiple clusters if you never asked for them?

Usually you have to specifically request a cluster to be created to get a new one. The only exception to this is when you upgrade a cluster, it will effectively create a new one and leave the old one in place.

share|improve this answer
    
Thanks for the iformantion.. I'm still processing it; but its all very handy. I ran the following command to get a list of installed packages: dpkg --get-selections and this is what I found listed for postgresql: postgres91 install postgresql install postgresql-9.1 install postgresql-client install postgresql-client-9.1 install postgresql-client-common install postgresql-common install Surely I don't need all of these packages, I feel removing them all and starting over. What do you think? –  Guided33 May 30 '12 at 15:08
1  
If I do a dpkg --list | grep postgres, I get a list showing postgresql postgresql-9.1 postgresql-client-9.1 postgresql-client-common postgresql-common ... These are all fine. postgresql is the main one and the others are the parts that make it up. I've not see one called postgres91. –  couling May 30 '12 at 15:22
1  
Ok. I uninstalled all of my postgres packages, including the postgre91. I also went in to my rails application and uninstalled the pg gem. The pg gem, I believed had a dependency on my having postgres installed locally. But when I ran attempted to reinstall the gem it installed itself just fine(with native extensions). Any idea how this occurred? When I initially tried to install this gem it required me to get postgres, and I am trying to re-create that state. –  Guided33 May 30 '12 at 17:14
1  
I'm afraid that's outside my scope of knowledge. –  couling May 31 '12 at 10:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.