Instancia
Advertencia:
Esta sección se mantiene como referencia pero su contenido puede ya no ser del todo útil por
la versión de programas usados: PostgreSQL 9.3 en Slackware Linux 14.1
A continuación se dan los pasos básicos para crear una instancia del SGBD PostgreSQL:
Crea un cluster de base de datos de PostgreSQL:
[root@servidor ~]# su - postgres [postgres@servidor ~]$ initdb -D /var/lib/pgsql/9.4/data 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 locales COLLATE: C CTYPE: en_US.UTF-8 MESSAGES: en_US.UTF-8 MONETARY: en_US.UTF-8 NUMERIC: en_US.UTF-8 TIME: 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 /var/lib/pgsql/9.4/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB creating configuration files ... ok creating template1 database in /var/lib/pgsql/9.4/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgSQL server-side language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections 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: postgres -D /var/lib/pgsql/9.4/data/ or pg_ctl -D /var/lib/pgsql/9.4/data/ -l logfile start
Inicia el demonio de PostgreSQL de forma manual:
[root@servidor ~]# sh /etc/rc.d/rc.postgresql start Starting PostgreSQL waiting for server to start.... done server started
Corroba su ejecución:
[root@servidor ~]# netstat -plutn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 659/postgres
Permite el acceso remoto (desde cualquier host en la red) al usuario postgres:
4.1. Asigna una contraseña al usuario postgres:
[root@servidor ~]# su - postgres postgres$ psql psql (9.4.0) Type "help" for help. postgres=# \password Enter new password: 1q2w Enter it again: 1q2w postgres=# \q
4.2. Edita el archivo
/var/lib/pgsql/9.4/data/postgresql.conf
y cambia la línea:#listen_addresses = 'localhost' # what IP address(es) to listen on;
por:
listen_addresses = '*' # what IP address(es) to listen on;
4.3. Edita
/var/lib/pgsql/9.4/data/pg_hba.conf
y agrega al final la siguiente línea:host all postgres all md5
4.4. Reinicia al demonio de PostgreSQL y verifica su ejecución en red:
[root@servidor ~]# sh /etc/rc.d/rc.postgresql restart Restarting PostgreSQL... waiting for server to shut down.... done server stopped server starting [root@servidor ~]# netstat -plutn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 721/postgres
Finalmente, para detener de forma manual al demonio de PostgreSQL ejecuta como root:
[root@servidor ~]# sh /etc/rc.d/rc.postgresql stop
Shutting down PostgreSQL...
waiting for server to shut down.... done
server stopped