PostgreSQL
 SQL >> Database >  >> RDS >> PostgreSQL

Installazione PostgreSQL 12 su CentOS 7

Questa guida mostra come installare PostgreSQL 12 su CentOS 7 e creare un primo database con utente dedicato.

Repository e pacchetti

yum install -y epel-release
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql12-server postgresql12-client postgresql12-contrib postgresql12-devel

Cartella dati e utente

mkdir /postgres/data
chown postgres:postgres /postgres/data
passwd postgres

Ambiente PostgreSQL

Aggiungere al file .bash_profile dell’utente postgres:

export PGDATA=/postgres/data
export PGUSER=postgres
export PGDATABASE=postgres
export PGPORT=5432
export PATH=$PATH:/usr/pgsql-12/bin

Inizializzazione

initdb -D /postgres/data
pg_ctl status
pg_ctl start

Configurazione postgresql.conf

Valori di esempio per un server con 32 GB RAM e 4 CPU:

listen_addresses = '*'
port = 5432
max_connections = 500
shared_buffers = 8GB
effective_cache_size = 24GB
maintenance_work_mem = 2GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
work_mem = 8388kB
min_wal_size = 1GB
max_wal_size = 4GB

Accesso e database

pg_ctl reload

In pg_hba.conf configurare le regole di autenticazione md5 per gli host necessari, quindi:

CREATE DATABASE tayfun
ENCODING = 'UTF-8'
LC_COLLATE = 'tr_TR.UTF-8'
LC_CTYPE = 'tr_TR.UTF-8'
TEMPLATE template0;

CREATE ROLE testuser PASSWORD 'testuser123!' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;

GRANT CONNECT ON DATABASE tayfun TO testuser WITH GRANT OPTION;
ALTER DATABASE tayfun OWNER TO testuser;