Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@servidor2:~# apt update && apt upgrade && apt install postgresql
- root@servidor2:~# netstat -tln
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
- tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
- tcp6 0 0 :::22 :::* LISTEN
- tcp6 0 0 ::1:631 :::* LISTEN
- tcp6 0 0 ::1:5432 :::* LISTEN
- root@servidor2:~# su - postgres
- postgres@servidor2:~$ psql
- psql (11.9 (Debian 11.9-0+deb10u1))
- Type "help" for help.
- postgres=# CREATE DATABASE prueba2;
- CREATE DATABASE
- postgres=# \l
- List of databases
- Name | Owner | Encoding | Collate | Ctype | Access privileges
- -----------+----------+----------+-------------+-------------+-----------------------
- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
- prueba2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
- template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
- | | | | | postgres=CTc/postgres
- template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
- | | | | | postgres=CTc/postgres
- (4 rows)
- postgres=# CREATE USER alvaro2 WITH PASSWORD 'alvaro2';
- CREATE ROLE
- postgres=# GRANT ALL PRIVILEGES ON DATABASE prueba2 TO alvaro2;
- GRANT
- postgres=# exit
- postgres@servidor2:~$ psql -h localhost -U alvaro2 -d prueba2
- Password for user alvaro2:
- psql (11.9 (Debian 11.9-0+deb10u1))
- SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
- Type "help" for help.
- ---------------------------------------------------------------------------
- -- La base de datos es bastante simple, pues se almacena información sobre los departamentos de una empresa, algo similar a la tabla DEPT del esquema SCOTT de Oracle. Como anteriormente hemos mencionado, en la tabla "Empleados" ubicada en el otro gestor, existe una columna que sería el resultado de una relación 1:N con la tabla "Departamentos", pero en esta ocasión, ambas tablas se encuentran ubicadas en gestores separados.
- prueba2=> CREATE TABLE Departamentos
- prueba2-> (
- prueba2(> Identificador NUMERIC(2),
- prueba2(> Nombre VARCHAR(20),
- prueba2(> Localizacion VARCHAR(15),
- prueba2(> CONSTRAINT pk_departamentos PRIMARY KEY (Identificador),
- prueba2(> CONSTRAINT locrellena CHECK (Localizacion IS NOT NULL)
- prueba2(> );
- CREATE TABLE
- prueba2=> INSERT INTO Departamentos
- prueba2-> VALUES (10, 'Administración', 'Sevilla');
- INSERT 0 1
- prueba2=> INSERT INTO Departamentos
- prueba2-> VALUES (20, 'Recursos Humanos', 'Barcelona');
- INSERT 0 1
- prueba2=> INSERT INTO Departamentos
- prueba2-> VALUES (30, 'Seguridad', 'Madrid');
- INSERT 0 1
- prueba2=> INSERT INTO Departamentos
- prueba2-> VALUES (40, 'Informática', 'Valencia');
- INSERT 0 1
- ---------------------------------------------------------------------------
- root@servidor2:~# ip a
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
- link/ether 08:00:27:15:e3:4b brd ff:ff:ff:ff:ff:ff
- inet 192.168.1.161/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
- valid_lft 86329sec preferred_lft 86329sec
- inet6 fe80::a00:27ff:fe15:e34b/64 scope link noprefixroute
- valid_lft forever preferred_lft forever
- root@servidor2:~# nano /etc/postgresql/11/main/postgresql.conf
- #listen_addresses = 'localhost'
- listen_addresses = '*'
- root@servidor2:~# nano /etc/postgresql/11/main/pg_hba.conf
- host all all 127.0.0.1/32 md5
- host all all all md5
- root@servidor2:~# systemctl restart postgresql
- root@servidor2:~# netstat -tln
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
- tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
- tcp6 0 0 :::22 :::* LISTEN
- tcp6 0 0 ::1:631 :::* LISTEN
- tcp6 0 0 :::5432 :::* LISTEN
Add Comment
Please, Sign In to add comment