L
L
lolowin322017-08-27 19:18:27
PostgreSQL
lolowin32, 2017-08-27 19:18:27

How to specify a different database storage location when creating a new postgres cluster?

Good day everyone, please help me figure out how to configure postgres so that all the databases that will be created are saved to a different directory, and not by default in /var/lib/postgresql/9.6/main/
ubuntu-srv-16.04x64
postgres 9.6 ( installed from this turnip 1c.postgrespro.ru/deb )
Thank you in advance for your answers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-08-27
@lolowin32

First, a little terminology to clearly speak the same language.
A postgresql cluster is one running postgres.
One cluster can contain several named databases, but they are all served by one running postgres.
There can be several postgres clusters on a physical machine.
Now what do you want to do?
* move the database directory to another location. Stop the database, copy the datadir to the right place with rsync, make a symlink in the old place (datadir in the config in this case does not even need to be edited, if you correct the paths in the config, then a symlink is not necessary)
* leave some databases in the default location, and some others - in another, but under the control of one cluster. You need to make a tablespace and use it. When creating a database, you can specify a tablespace, which will be considered by default for all objects in this database (but you can override it for each object)
* launch a separate cluster. You simply cannot insert two bases in the same place. The corresponding, and usually required, parameter in initdb plus specifying datadir in the config or database startup line (depending on how the database will be started and where else the config is located). And for a very nice wrapper in debian and ubuntu pg_createcluster , the --datadir parameter is also immediately available,
see alsoHow to correctly change the location of the postgresql-9.2.18.rl7 database?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question