S
S
seekinganswers2017-05-19 11:43:33
linux
seekinganswers, 2017-05-19 11:43:33

How to initialize Postgresql files?

Good afternoon, dear Toasters! I ask you to instruct the young padawan in *nix systems if possible!
And now to business.
Postgresql 9.6 was installed on UBUNTU 16.04. It was necessary to set a different folder for the databases. Used the following algorithm of actions:

удалил текущий каталог кластера базы данных:

sudo rm -rf /var/lib/postgresql

- установил пароль для UNIX-пользователя postgres:

sudo passwd postgres

- создал новый каталог кластера базы данных:

sudo mkdir /media/ad/data/bd1c

- установил UNIX-пользователя postgres владельцем каталога /var/lib/pgsql:

sudo chown -R postgres:postgres media/ad/data/bd1c

- от имени UNIX-пользователя postgres инициализировал кластер базы данных с новым каталогом и новой локалью:

su postgres -c '/usr/lib/postgresql/9.6/bin/initdb -D media/ad/data/bd1c --locale=ru_RU.UTF-8'

- от имени суперпользователя в файле /etc/postgresql/9.6/main/postgresql.conf изменил значение каталога кластера базы данных на новое размещение, т.е. в приведенном примере строку
data_directory = '/var/lib/postgresql/9.4/main'
привел к виду
data_directory = '/media/ad/data/bd1c

And in after reboot:
sudo service postgresql status
postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: e
   Active: active (exited) since Пт 2017-05-19 10:53:42 MSK; 58min ago
  Process: 14061 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 14061 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/postgresql.service

su - postgres
psql -l
psql: не удалось подключиться к серверу: Нет такого файла или каталога
  Он действительно работает локально и принимает
  соединения через доменный сокет "/var/run/postgresql/.s.PGSQL.5432"?

And the young padawan went to the forums to look for answers, found the answer:
uncomment and initialize the line unix_socket_directory = '/var/run/postgresql/'

And then attention in /etc/postgresql/9.6/main/postgresql.conf it is uncommented, but here it was commented out /media/ad/Data/bd1c/postgresql.conf and then it immediately fell out which postgresql.conf is more important and how to find who links to it. Or am I not digging correctly at all?
Please guide the young Padawan on the right path! Thank you in advance for your answers! I want to understand the process so that in the future such errors would not arise, or at least I could immediately understand what was happening :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2017-05-19
@melkij

sudo rm -rf /var/lib/postgresql

This was the user's home dir, not the cluster directory. Cluster directory in default distribution in /var/lib/postgresql/pg_version/another_main_or_base_directory
Let's say.
Pay attention to the relative path. I'm not sure where initdb ended up trying to make a base.
resulted in
data_directory = '/var/lib/pgsql'

? Where did this come from?
The one specified in the postgres startup arguments. Explicitly through -c config_file or located in PGDATA if there is no argument with the config name.

P
Pustovut, 2017-05-19
@Pustovut

For example on Centos 7 with latest Postgres:
/usr/pgsql-9.6/bin/postgresql96-setup initdb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question