Instalar postgres
1 |
sudo apt-get install postgresql |
Entrar como usuario postgres
1 |
su postgres |
1 |
psql -U postgres |
Crear usuario
1 |
createuser NOMBRE_USUARIO |
Crear base de datos
Se necesita antes iniciar sesión en la cuenta postgres:
1 |
sudo su postgres |
Crear base de datos:
1 |
createdb NOMBRE_DB |
Ver las bases de datos existentes:
1 |
psql -l |
1 2 3 4 5 6 7 8 9 10 11 |
$ psql -l Listado de base de datos Nombre | Dueño | Codificación | Collate | Ctype | Privilegios ---------------+----------+--------------+-------------+-------------+----------------------- db1 | postgres | UTF8 | es_ES.UTF-8 | es_ES.UTF-8 | postgres | postgres | UTF8 | es_ES.UTF-8 | es_ES.UTF-8 | template0 | postgres | UTF8 | es_ES.UTF-8 | es_ES.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | es_ES.UTF-8 | es_ES.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 filas) |
Con la herramienta psql
1 |
\l |
Comprobar el estado del servicio postgres (Debian)
1 |
/etc/init.d/postgresql status |
1 2 3 4 5 6 |
root@server:/# /etc/init.d/postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled) Active: active (exited) since mié 2018-10-24 11:19:22 CEST; 29min ago Main PID: 26175 (code=exited, status=0/SUCCESS) CGroup: /system.slice/postgresql.service<br> |
Listar las tablas de un base de datos
Acceder a la base de datos
1 |
psql -U postgres -d nombredb |
1 |
\dt |
Salir de la terminal psql
1 |
\q |
Exportar base de datos
1 |
pg_dump -U username dbname > dbexport.pgsql |
Conexión a la base de datos
1 |
psql -h postgresql.com -U user -d dbname |
Enlaces de interés:
https://iie.fing.edu.uy/~vagonbar/debian/debian30/postgresql/postgres.htm
https://doc.odoo.com/es/install/linux/postgres/
https://www.digitalocean.com/community/tutorials/como-instalar-y-utilizar-postgresql-en-ubuntu-16-04-es
https://www.linuxito.com/programacion/337-como-listar-tablas-y-bases-de-datos-en-postgres
https://doc.odoo.com/es/install/linux/postgres/
https://www.digitalocean.com/community/tutorials/como-instalar-y-utilizar-postgresql-en-ubuntu-16-04-es
https://www.linuxito.com/programacion/337-como-listar-tablas-y-bases-de-datos-en-postgres