Postgresql – Will PostgreSQL server work if I install the service in mounted partition

postgresqlpostgresql-9.1restore

I have created all tablespaces (only tables created in these tablespaces) in mounted partition, But db is available in pg_default tablespace (root partition where postgresql installed).

I am facing problem with memory since my root partition having only 10 GB. I have verified the data folder (/opt/postgresql/9.1/data/), and noticed few things.

  1. /opt/postgresql/9.1/data/base directory having more data
  2. pg_largeobject table is having more data

So, I planned to do following activity,

  1. Take the full backup of existing database(s) – custom format (*.sql)
  2. Uninstall the postgresql from the root directory, using uninstall.sh (which is available the postgresql path)
  3. Install the new postgresql in mounted path (/newly/mounted/remote/path/postgresql/)

If I do above steps, will postgresql service start and work without any issue?
(if no issue, I will restore the database backup)

Any suggestion?

(using postgresql-9.1)

Best Answer

Yes, you can move your base directory to any location you wish where the postgres service has write access and enough storage available. There are a few things to note

  1. your startup script needs to set it's PGDATA directory correctly to the new location
  2. your clients that connect locally have to set their PGDATA to the new location. Tablespaces in postgres add a lot to complexity. Better is to try to prevent them being used at all.

Tablespaces are directories that are pointed to by symbolic links in $PGDATA so you can keep them if you like. They will be resolved.