Notas

Notas, scripts, algoritmos de uso diario y documentación de algunos proyectos.

View on GitHub
27 July 2021

PostgreSQL

by Juan Manuel González Garzón

PostgreSQL

Instalar y configurar

# https://www.postgresql.org/download/linux/ubuntu/
# https://www.pgadmin.org/download/pgadmin-4-apt/

# Install client/server
$ sudo dnf install postgresql postgresql-server postgresql-devel

tail -f /var/log/postgresql/postgresql-13-main.log
# Initialize PG cluster
pg_ctlcluster 13 main start
$ sudo postgresql-setup --initdb --unit postgresql

# Enable postgresql server
$ sudo systemctl enable postgresql

# Install Database Managers
$ sudo dnf install phpPgAdmin pgadmin3

# login as DB admin
$ sudo su - postgres

# Create Database, User and grant access
$ sudo su - postgres

# Create user and put the passwod
$ createuser testuser -P
$ createuser juanmanuel -P
#Password = piedePostgres_4

#Create database and grant acces to the user
$ createdb testdb --owner testuser
$ createdb bitacora --owner juanmanuel

Edit the postgres config to allow conections

vim ~/data/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident
 =============END =============
sudo systemctl restart postgresql

Open ports in the firewall

$ # make it last after reboot
$ firewall-cmd --permanent --add-port=5432/tcp
$ # change runtime configuration
$ firewall-cmd --add-port=5432/tcp

Creditos y referencias

Postgre icons created by Freepik - Flaticon

tags: