tips:db:postgres

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:db:postgres [2017/11/21 13:43] – [pgmodeler] scipiotips:db:postgres [2019/03/13 09:55] (current) – [Basic operations] scipio
Line 21: Line 21:
 ===== Basic operations ===== ===== Basic operations =====
  
-create role (user) 
 <code> <code>
--- User: gianoauth +# list databases 
-DROP USER gianoauth;+\l
  
 +# connect to database
 +\c giano
 +
 +# list schema
 +\dn
 +
 +# list tables in schema
 +\dt auth.*
 +
 +# describe table
 +\d+ auth.users
 +
 +# list of installed extensions
 +\dx
 +
 +# enable expanded display
 +\x
 +</code>
 +
 +set search path for database
 +<code>
 +psql <database>
 +ALTER DATABASE database_name SET search_path TO schema_name,public;
 +</code>
 +
 +
 +drop role gianoauth
 +<code>
 +REASSIGN OWNED BY gianoauth TO postgres;
 +DROP OWNED BY gianoauth;
 +DROP USER IF EXISTS gianoauth;
 +</code>
 +
 +create role gianoauth
 +<code>
 CREATE USER gianoauth WITH CREATE USER gianoauth WITH
 +  ENCRYPTED PASSWORD 'xxx'
   LOGIN   LOGIN
   NOSUPERUSER   NOSUPERUSER
Line 33: Line 68:
   NOCREATEROLE   NOCREATEROLE
   NOREPLICATION;   NOREPLICATION;
 +</code>
  
-ALTER USER gianoauth SET search_path TO gianoauth; +... create database and schemas ...
-ALTER ROLE gianoauth IN DATABASE giano SET search_path TO gianoauth;+
  
-GRANT ALL PRIVILEGES ON  SCHEMA gianoauth TO gianoauth; +grant operations on schema auth to role gianoauth 
-GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA gianoauth TO gianoauth; +<code> 
-GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA gianoauth TO gianoauth;+GRANT ALL PRIVILEGES ON  SCHEMA auth TO gianoauth; 
 +ALTER DEFAULT PRIVILEGES FOR USER postgres IN SCHEMA auth GRANT SELECT ON TABLES TO gianoauth; 
 +ALTER DEFAULT PRIVILEGES FOR USER postgres IN SCHEMA auth GRANT SELECT, USAGE ON SEQUENCES TO gianoauth
 +</code> 
 + 
 +on database giano set search path on user gianoauth to search first in schema auth 
 +<code> 
 +ALTER USER gianoauth SET search_path TO auth; 
 +ALTER ROLE gianoauth IN DATABASE giano SET search_path TO auth; 
 +</code> 
 + 
 +create superuser <admin> with password 
 +<code> 
 +createuser -P -s -e admin 
 +</code> 
 + 
 + 
 +create user and database for sentry 
 +<code> 
 +CREATE ROLE sentry WITH PASSWORD 'blabla' LOGIN; 
 +CREATE DATABASE sentry ENCODING 'UTF8' OWNER sentry;
 </code> </code>
 ==== developer containers ===== ==== developer containers =====
Line 69: Line 124:
 apt install wget python3-pip apt install wget python3-pip
 pip3 install -U pip pip3 install -U pip
-cd /tmp +pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.2/pip/pgadmin4-4.2-py2.py3-none-any.whl
-wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.0/pip/pgadmin4-2.0-py2.py3-none-any.whl +
-pip install ./pgadmin4-2.0-py2.py3-none-any.whl+
  
 # define ip binding # define ip binding
Line 110: Line 163:
  
 <code> <code>
-PG_VERSION=0.9.1-alpha+PG_VERSION=0.9.1-beta1
  
 # for building, can remove after install # for building, can remove after install
-sudo apt install make g++ qt5-qmake libxml2-dev libpq-dev pkg-config libqt5svg5-dev+sudo apt install -y make g++ qt5-qmake libxml2-dev libpq-dev pkg-config libqt5svg5-dev
  
 # runtime dependencies # runtime dependencies
-sudo apt install qt5-default libqt5svg5 postgresql-server-dev-all+sudo apt install -y qt5-default libqt5svg5 postgresql-server-dev-all
 cd /usr/local/src cd /usr/local/src
-sudo apt install wget+sudo apt install -y wget
 wget https://github.com/pgmodeler/pgmodeler/archive/v${PG_VERSION}.tar.gz wget https://github.com/pgmodeler/pgmodeler/archive/v${PG_VERSION}.tar.gz
 tar xvzf v${PG_VERSION}.tar.gz tar xvzf v${PG_VERSION}.tar.gz
-cd pgmodeler-0.9.1-alpha/+cd pgmodeler-${PG_VERSION}/
 qmake pgmodeler.pro qmake pgmodeler.pro
 make -j 4 make -j 4
  • tips/db/postgres.1511268228.txt.gz
  • Last modified: 2017/11/21 13:43
  • by scipio