Практикум
Подготовка
-
Остановите сервер:
[student@p620 ~]$ sudo systemctl stop postgresql
[student@p620 ~]$ sudo systemctl status postgresql ○ postgresql.service - Runners PostgreSQL service
Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sat 2024-11-09 15:49:30 MSK; 7s ago
Process: 28517 ExecStartPre=/bin/mkdir -p /var/run/postgresql (code=exited, status=0/SUCCESS)
Process: 28519 ExecStartPre=/bin/chown -R postgres:postgres /var/run/postgresql (code=exited,
status=0/SUCCESS)
Process: 28520 ExecStart=/bin/bash -i -c /usr/pangolin-6.2.0/bin/postgres -D /pgdata/06/data
(code=exited, status=0/SUCCESS)
Main PID: 28520 -
В сеансе
postgres
переименуйте каталог данных кластера и создайте пустой новый каталог со старым именем - оно задано переменной окруженияPGDATA
:[postgres@p620 ~]$ cd $PGDATA
[postgres@p620 data]$ cd ..
[postgres@p620 06]$ pwd /pgdata/06
[postgres@p620 06]$ ls data
[postgres@p620 06]$ mv -v data{,.bak} renamed 'data' -> 'data.bak'
[postgres@p620 06]$ ls data.bak
[postgres@p620 06]$ mkdir $PGDATA
[postgres@p620 06]$ ls data data.bak
Кластер баз данных
-
Проверьте настройки системной локали:
[postgres@p620 06]$ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL= -
Выведите список настроек, в соответствии с которыми
initdb
будет создавать кластер баз данных:[postgres@p620 06]$ initdb -s
The files belonging to this database system will be owned by user "postgres". This user must also own the server process.
VERSION=15.5
PGDATA=/pgdata/06/data
share_path=/usr/pangolin-6.2.0/share
PGPATH=/usr/pangolin-6.2.0/bin
POSTGRES_SUPERUSERNAME=postgres
POSTGRES_BKI=/usr/pangolin-6.2.0/share/postgres.bki
POSTGRESQL_CONF_SAMPLE=/usr/pangolin-6.2.0/share/postgresql.conf.sample
PG_HBA_SAMPLE=/usr/pangolin-6.2.0/share/pg_hba.conf.sample
PG_IDENT_SAMPLE=/usr/pangolin-6.2.0/share/pg_ident.conf.sample
PG_QUOTA_SAMPLE=/usr/pangolin-6.2.0/share/pg_quota.conf.sample -
Создайте кластер данных командой
initdb
с настройками по умолчанию. Не указывайте опцию-k
или--data-checksums
. Требуется создать кластер данных без защиты данных контрольными суммами:[postgres@p620 06]$ initdb
The files belonging to this database system will be owned by user "postgres". This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /pgdata/06/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ...
"/usr/pangolin-6.2.0/bin/postgres" --check -F -c log_checkpoints=false -c is_initdb=true -c
max_connections=100 -c shared_buffers=1000 -c dynamic_shared_memory_type=posix < "/dev/null" >
"/dev/null" 2>&1
100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Moscow
creating configuration files ... ok
running bootstrap script ... 2024-11-09 16:15:06.155 MSK [31377] WARNING:
/usr/pangolin-6.2.0/bin/postgres: Could not init KMS connection. Error: -52 (failed to lock file)
ok
performing post-bootstrap initialization ... 2024-11-09 16:15:06.375 MSK [31379] WARNING: postgres:
Could not init KMS connection. Error: -52 (failed to lock file)
ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and
--auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /pgdata/06/data -l logfile start -
Проверьте, что сервер может стартовать с вновь созданным кластером данных:
[student@p620 ~]$ sudo systemctl start postgresql
[student@p620 ~]$ sudo systemctl status postgresql ● postgresql.service - Runners PostgreSQL service
Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2024-11-09 19:25:10 MSK; 6s ago
Process: 31726 ExecStartPre=/bin/mkdir -p /var/run/postgresql (code=exited, status=0/SUCCESS)
Process: 31727 ExecStartPre=/bin/chown -R postgres:postgres /var/run/postgresql (code=exited,
status=0/SUCCESS)
Main PID: 31728 (postgres)
Tasks: 10 (limit: 4652)
Memory: 28.6M
CPU: 164ms
CGroup: /system.slice/postgresql.service
├─ 31728 /usr/pangolin-6.2.0/bin/postgres -D /pgdata/06/data
├─ 31752 "postgres: checkpointer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" "" "" "" ""
├─ 31753 "postgres: background writer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" ""
├─ 31755 "postgres: idle sessions terminator " "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" ""
├─ 31756 "postgres: walwriter " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" "" "" "" "" "" ""
├─ 31757 "postgres: license checker " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" "" ""
├─ 31758 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" ""
├─ 31759 "postgres: autounite launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" "" "" "" "" ""
"" "" ""
├─ 31760 "postgres: integrity check launcher " "" "" "" "" "" "" "" "" "" "" "" "" ""
└─ 31761 "postgres: logical replication launcher " "" "" "" "" "" "" "" "" "" "" "" ""
Nov 09 19:25:10 p620.class.edu bash[31728]: 2024-11-09 19:25:10.421 MSK [31728] LOG: listening on
IPv6 address "::1", port 5432
Nov 09 19:25:10 p620.class.edu bash[31728]: 2024-11-09 19:25:10.422 MSK [31728] LOG: listening on
IPv4 address "127.0.0.1", port 5432
Nov 09 19:25:10 p620.class.edu bash[31728]: 2024-11-09 19:25:10.430 MSK [31728] LOG: listening on
Unix socket "/tmp/.s.PGSQL.5432"
Nov 09 19:25:10 p620.class.edu bash[31754]: 2024-11-09 19:25:10.449 MSK [31754] LOG: database
system was shut down at 2024-11-09 16:15:06 MSK
Nov 09 19:25:10 p620.class.edu bash[31755]: 2024-11-09 19:25:10.454 MSK [31755] LOG: idle
terminator started
Nov 09 19:25:10 p620.class.edu bash[31757]: 2024-11-09 19:25:10.490 MSK [31757] LOG: License
checker started
Nov 09 19:25:10 p620.class.edu bash[31728]: 2024-11-09 19:25:10.498 MSK [31728] LOG: database
system is ready to accept connections
Nov 09 19:25:10 p620.class.edu bash[31760]: 2024-11-09 19:25:10.499 MSK [31728] LOG: Start
integrity check launcher
Nov 09 19:25:10 p620.class.edu bash[31760]: 2024-11-09 19:25:10.502 MSK [31760] LOG: Start of
integrity check
Nov 09 19:25:10 p620.class.edu systemd[1]: Started Runners PostgreSQL service.
[student@p620 ~]$ ps f -C postgres
PID TTY
31728 ?
31752 ?
31753 ?
31755 ?
31756 ?
31757 ?
31758 ?
31759 ?
31760 ?
31761 ?
STAT TIME COMMAND
Ss 0:00 /usr/pangolin-6.2.0/bin/postgres -D /pgdata/06/data
Ss 0:00 \_ postgres: checkpointer
Ss 0:00 \_ postgres: background writer
Ss 0:00 \_ postgres: idle sessions terminator
Ss 0:00 \_ postgres: walwriter
Ss 0:00 \_ postgres: license checker
Ss 0:00 \_ postgres: autovacuum launcher
Ss 0:00 \_ postgres: autounite launcher
Ss 0:00 \_ postgres: integrity check launcher
Ss 0:00 \_ postgres: logical replication launcher -
Остановите сервер. Теперь необходимо убедиться в том, что контрольные суммы не включены:
[student@p620 ~]$ sudo systemctl stop postgresql
[student@p620 ~]$ sudo -iu postgres
[postgres@p620 ~]$ pg_checksums -D $PGDATA -c
pg_checksums: error: data checksums are not enabled in clusterКоманда
pg_checksums
с опцией-c
проверяет, включены ли контрольные суммы. -
Включите контрольные суммы и снова проверьте. Сервер должен быть остановлен:
[postgres@p620 ~]$ pgrep -l postgres
[postgres@p620 ~]$ pg_checksums -D $PGDATA -e Checksum operation completed
Files scanned: 1011
Blocks scanned: 3476
Files written: 827
Blocks written: 3476
pg_checksums: syncing data directory
pg_checksums: updating control file
Checksums enabled in clusterКонтрольные суммы включены.
Начальная настройка экземпляра
-
В сеансе
postgres
перейдите в каталогPGDATA
и внесите изменения в конфигурационный файлpostgresql.conf
, предварительно сохранив его копию:[postgres@p620 ~]$ cd $PGDATA
[postgres@p620 data]$ cp -v postgresql.conf{,.orig} 'postgresql.conf' -> 'postgresql.conf.origНастройка для прослушивания всех интерфейсов:
[postgres@p620 data]$ tee -a postgresql.conf <<< "listen_addresses = '*'" listen_addresses = '*'