Postgres and Volumes
gitlherme
HOBBYOP

a year ago

Hello, team!

I have a little question about postgres template and volumes.

When a postgre service is created, also a volume is created together, right?

If I remove the service, but keep the volume, can I create a new service and connect with this volume to get the old data? If yes, how can I do that?

PID: 07d68a18-6f03-415d-a1c0-f353b7610ec3

6 Replies

gitlherme
HOBBYOP

a year ago

Some help here please? <:sadge:1244710822752813098>


a year ago

When a postgre service is created, also a volume is created together, right

correct

If I remove the service, but keep the volume, can I create a new service and connect with this volume to get the old data? If yes, how can I do that?

Yes you can, you would just need to remove the new volume and mount the old volume in the same place, and then you would need to set the correct password to the same password as the original database had

but why?


gitlherme
HOBBYOP

a year ago

Thanks for the answer, Brody!

Let's say maybe I removed my production postgres database <:kekw:788259314607325204>

I was mounting in the same path but the databse connection wasn't working. I think that is because I was using the new credentials instead of the old ones. I will try to use it now, really thanks!


a year ago

no problem!


echohack
EMPLOYEE

a year ago

Postgres can be a bit of a bear to restart sometimes :\

Just to add a few more tricks for you, there are some lifecycle things you may need to consider, like reloading your config

pg_reload_config() {
  psql ${primary_connect_string} -d postgres -t -c 'SELECT pg_reload_conf()'
}

or doing something to wake up an NFS connection before writing the volume

# this read operation will re-awaken any flaky NFS connections
# before attempting the mkdir write operation
stat {{cfg.wal_archive.path}} {{cfg.pg_dump.path}} || true

mkdir -p {{pkg.svc_config_path}}/conf.d \
 {{pkg.svc_var_path}}/pg_stat_tmp \
 {{pkg.svc_data_path}}/pgdata \
 {{cfg.wal_archive.path}} \
 {{cfg.pg_dump.path}}

Hopefully you're not needing to reconfigure HA/Leader or WAL replication, that's a bit more hairy to untangle should you get in a bad state.


a year ago

Postgres and Volumes


Loading...