Herramientas de usuario

Herramientas del sitio


db:postgresql

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisión
Revisión previa
db:postgresql [2020/08/04 13:54] – [Procesos y consultas] grillodb:postgresql [2020/12/09 16:06] (actual) – [Debug] grillo
Línea 22: Línea 22:
 $ ps -ef | grep "postgres: " $ ps -ef | grep "postgres: "
 ``` ```
 +
 +VER SERVIDOR AL QUE ESTOY CONECTADO
 +```
 +\conninfo
 +```
 +```
 +SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;
 +```
 +```
 +SELECT inet_server_addr() ip, inet_server_port() port;
 +```
 +
  
  
Línea 41: Línea 53:
 $ psql -U prueba -h localhost -W -d dbprueba $ psql -U prueba -h localhost -W -d dbprueba
 $ psql -U prueba -h localhost -W "dbname=dbprueba sslmode=require" $ psql -U prueba -h localhost -W "dbname=dbprueba sslmode=require"
 +```
 +
 +usuario "prueba" en servidor "localhost" con clave "pepe" en base "dbprueba" con esquema por defecto "pruebaschema"
 +```
 +$ psql -U prueba -h localhost -W "dbname=dbprueba sslmode=require options=--search_path=pruebaschema"
 +```
 +
 +
 +LISTAR ESQUEMAS DE UNA BASE
 +```
 +postgres=# \dp
 +postgres=# select schema_name from information_schema.schemata;
 +```
 +
 +VER ESQUEMA ACTUAL
 +```
 +postgres=# SHOW search_path;
 +```
 +
 +CONECTARSE A UN ESQUEMA
 +```
 +postgres=# SET search_path TO myschema,public;
 ``` ```
  
Línea 95: Línea 129:
  
 VER TABLAS DE LA BASE VER TABLAS DE LA BASE
-``` postgres=# \dt ``` +``` 
-``` mydb=# SELECT * FROM "pg_tables"; ```+postgres=# \dt 
 +mydb=# SELECT * FROM "pg_tables"; 
 +```
  
 VER TABLAS LISTAS Y SECUENCIAS DE LA BASE VER TABLAS LISTAS Y SECUENCIAS DE LA BASE
-``` postgres=# \d ```+``` 
 +postgres=# \d 
 +```
  
 CAMBIAR DUEÑO DE UNA TABLA CAMBIAR DUEÑO DE UNA TABLA
 +
 tabla "tabla" al usuario "user" tabla "tabla" al usuario "user"
-``` mydb=#  ALTER TABLE tabla owner to user; ```+``` 
 +mydb=#  ALTER TABLE tabla owner to user; 
 +```
  
  
Línea 231: Línea 272:
 ``` ```
 $ kill procpid $ kill procpid
 +```
 +
 +
 +VER USUARIOS CONECTADOS A UNA BASE labase
 +```
 +mydb=# SELECT usename,client_addr FROM pg_stat_activity WHERE datname = 'labase';
 ``` ```
  
Línea 237: Línea 284:
  
 EXPORTAR TODAS LAS BASES EXPORTAR TODAS LAS BASES
-``` $ pg_dumpall >bases.sql ```+``` 
 +$ pg_dumpall >bases.sql 
 +```
  
 EXPORTAR BASE EXPORTAR BASE
 +
 base "temp" base "temp"
-``` $ pg_dump test >text.sql ```+``` 
 +$ pg_dump test >text.sql 
 +``` 
 dump de base "prueba" con formato custom para después importar dump de base "prueba" con formato custom para después importar
-``` $ pg_dump -Fc prueba > prueba.dump ```+``` 
 +$ pg_dump -Fc prueba > prueba.dump 
 +```
  
 IMPORTAR BASE IMPORTAR BASE
 +
 importar a base "prueba" desde archivo dump "prueba.dump" con formato custom importar a base "prueba" desde archivo dump "prueba.dump" con formato custom
-``` $ pg_restore --clean --role=postgres --dbname=prueba --no-owner prueba.dump ```+``` 
 +$ pg_restore --clean --role=postgres --dbname=prueba --no-owner prueba.dump 
 +```
  
 +
 +## Actualizar datos con unl desde pc sin acceso al filesystem
 +
 +Procedimiento para actualizar datos tomándolos desde un archivo csv|unl ubicado en una pc cliente del servidor. La limitación es que el comando `copy` sólo levanta archivos del filesystem local del servidor.
 +```
 +cat  /home/cliente/actas_sin_objeto_para_actualizar.csv| psql "sslmode=require host=postgre.server.com dbname=labase" --username=cliente -W -c "create temp table tmp_datos_domicilio (
 +    objeto_id          bigint,
 +    tipo_objeto        character varying(20),
 +    objeto             character varying(500),
 +    acta_id            bigint,
 +    t_acta             integer,
 +    nro_acta           bigint,
 +    serie              character varying(2),
 +    fecha_acta         timestamp without time zone,
 +    lugar_acta_id      bigint,
 +    ref_geografica     character varying(255),
 +    cant_encontradas   integer,
 +    cod_calle          integer,
 +    nom_calle          character varying(50),
 +    cod_intersec       integer,
 +    nom_intersec       character varying(50),
 +    altura             integer,
 +    letra_a            character varying(5),
 +    bis_a              boolean,
 +    sec                integer,
 +    mnz                integer,
 +    gra                integer,
 +    div                integer,
 +    sdiv               integer,
 +    carpeta            integer,
 +    catastral          character varying(25));
 +copy from stdin;"
 +
 +copy tmp_datos_domicilio from stdin delimiter ',';
 +```
  
 ## Replicación ## Replicación
  
 PROCESOS CORRIENDO PROCESOS CORRIENDO
 +
 en el master en el master
-``` $ ps -ef | grep sender ```+``` 
 +$ ps -ef | grep sender 
 +``` 
 en el esclavo en el esclavo
-``` $ ps -ef | grep receiver ```+``` 
 +$ ps -ef | grep receiver 
 +```
  
 ESTADO DE LA REPLICA ESTADO DE LA REPLICA
-``` $ pg_lsclusters ```+``` 
 +$ pg_lsclusters 
 +```
  
 VER ESCLAVOS CONECTADOS AL MASTER VER ESCLAVOS CONECTADOS AL MASTER
 +
 en el master en el master
-``` $ psql -c "select client_addr, state, sent_location, write_location, flush_location, replay_location from pg_stat_replication;" ```+``` 
 +$ psql -c "select client_addr, state, sent_location, write_location, flush_location, replay_location from pg_stat_replication;" 
 +```
  
 VER RETRASO EN EL ESCLAVO VER RETRASO EN EL ESCLAVO
 +
 en el esclavo en el esclavo
-``` postgres=# select now() - pg_last_xact_replay_timestamp() AS replication_delay; ```+``` 
 +postgres=# select now() - pg_last_xact_replay_timestamp() AS replication_delay; 
 +```
                                                                                                                                                                                          
  
db/postgresql.1596549271.txt.gz · Última modificación: 2020/08/04 13:54 por grillo