pg_dropcluster

If you’re running PostgreSQL on Debian there are some friendly wrapper commands for the underlying PostgreSQL commands. Things like pg_lscluster to list all postgresql clusters running on a box. These make life a little nicer for your PostgreSQL administrator. Today I tried pg_dropcluster for the first time. And it worked! ..mostly.

[postgres]: pg_lsclusters
Version Cluster   Port Status Owner    Data directory                     Log file
9.0     sqst      5436 down   postgres /var/lib/postgresql/9.0/sqst       /var/log/postgresql/postgresql-9.0-sqst.log
9.0     tabt      5439 online postgres /var/lib/postgresql/9.0/tabt       /var/log/postgresql/postgresql-9.0-tabt.log
[postgres]3: pg_ctlcluster 9.0 tabt stop
[postgres]4: pg_dropcluster 9.0 tabt
[postgres]5: pg_lsclusters
Version Cluster   Port Status Owner    Data directory                     Log file
9.0     sqst      5436 down   postgres /var/lib/postgresql/9.0/sqst       /var/log/postgresql/postgresql-9.0-sqst.log
[postgres]: cd /postgres
[postgres]: find . -name tabt
./backups/tabt
./9.0/tabt
[postgres]: cd 9.0/tabt
[postgres]: ls -la
total 20
drwx------ 13 postgres postgres 4096 2012-03-26 09:43 .
drwxr-xr-x  9 postgres postgres   86 2012-01-18 12:35 ..
drwx------  6 postgres postgres   50 2012-01-18 14:12 base
drwx------  2 postgres postgres 4096 2012-03-26 09:43 global
drwx------  2 postgres postgres   17 2012-01-18 12:37 pg_clog
drwx------  2 postgres postgres 4096 2012-03-26 01:00 pg_log
drwx------  4 postgres postgres   34 2012-01-18 12:37 pg_multixact
drwx------  2 postgres postgres   17 2012-01-18 14:14 pg_notify
drwx------  2 postgres postgres    6 2012-03-26 09:43 pg_stat_tmp
drwx------  2 postgres postgres   17 2012-01-18 12:37 pg_subtrans
drwx------  2 postgres postgres    6 2012-01-18 12:37 pg_tblspc
drwx------  2 postgres postgres    6 2012-01-18 12:37 pg_twophase
-rw-------  1 postgres postgres    4 2012-01-18 12:37 PG_VERSION
drwx------  3 postgres postgres   89 2012-01-18 14:19 pg_xlog
-rw-------  1 postgres postgres  133 2012-01-18 14:14 postmaster.opts
lrwxrwxrwx  1 root     root       36 2012-01-18 12:39 server.crt
lrwxrwxrwx  1 root     root       38 2012-01-18 12:40 server.key
[postgres]: du -sh .
54M	.
[postgres]: pwd
/pgres01/postgres/9.0/tabt

So, the command didn’t remove our backups (this is a GOOD thing!) as there is no information about this directory in our postgresql.conf file (which was successfully deleted along with our pg_hba.conf) but it didn’t follow the symbolic link that we use for our data directories. I can see how it is dangerous to follow some symbolic links as I guess it’s theoreticaly possible for things like log direcories to be shared across clusters but quite frankly if you do something as unusual as this you deserve what you get :). Imho, when you drop a cluster you should also drop the data directories.. Also, the WAL files weren’t removed. These are part of our backup so that’s also a good thing!

Advertisements

About dnadba

I work with databases and stuff
This entry was posted in PostgreSQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s