Changes between Initial Version and Version 1 of members/GRIP-UQAM/Postgres


Ignore:
Timestamp:
Aug 22, 2016, 5:40:06 PM (9 years ago)
Author:
Grip Uqam
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • members/GRIP-UQAM/Postgres

    v1 v1  
     1= Some PostgreSQL commands =
     2* List of DB with parameters
     3{{{#!sh
     4$ psql postgres --command="\l"
     5}}}
     6* Create user
     7{{{#!sh
     8postgres:~$ createuser -D -R -S <UNIX user>
     9}}}
     10* Create DB
     11{{{#!sh
     12postgres:~$ createdb -O <postgres user> <database name>
     13}}}
     14* Backup
     15{{{#!sh
     16$ pg_dump -Fc --verbose --file=<file name (.data)> <database name>
     17}}}
     18 * Drupal backup https://www.drupal.org/node/2607038#comment-11204141
     19{{{#!sh
     20PGPASSWORD="" pg_dumpall -w -U <user> -h /var/run/postgresql -p 5432 -l user -f /.../<user>-2016-07-22-10-17-49.sql
     21}}}
     22* Restore the data base as a different user eg. to clone a Drupal website (bad idea to clone a drupal website)
     23{{{#!sh
     24$ pg_restore --verbose --no-owner --no-privileges --dbname=<database name> <file name (.data)>
     25}}}
     26* Mark cache tables as {{{UNLOGGED}}} Postgres <= 9.4 (Debian 8.0 Jessie)
     27{{{#!sh
     28...=> \d name
     29...
     30...=> CREATE UNLOGGED TABLE toto (id serial, ...);
     31}}}
     32  * http://www.postgresql.org/docs/9.4/static/sql-createtable.html
     33  * It is easier to get schema from pgAdmin III, maybe on development server.
     34* Mark cache tables as {{{UNLOGGED}}} Postgres >= 9.5
     35{{{#!sql
     36ALTER TABLE name SET UNLOGGED;
     37}}}
     38  * http://www.postgresql.org/docs/current/static/sql-altertable.html
     39  * //[https://stackoverflow.com/questions/9153157/postgres-hstore-vs-redis-performance-wise Postgres Hstore vs. Redis - performance wise]//
     40* {{{-E}}} or {{{--echo-hidden}}} See SQL requests send by {{{psql}}} for commands like {{{\l}}} ({{{\list}}})
     41{{{#!sh
     42$ psql --echo-hidden --dbname postgres
     43}}}
     44 * http://www.postgresql.org/docs/9.4/static/app-psql.html
     45 * http://www.postgresql.org/message-id/18380.994171549@sss.pgh.pa.us
     46 * How do I get a list of databases in a Postgresql database ?
     47* [http://www.thegeekstuff.com/2009/04/15-practical-postgresql-database-adminstration-commands 15 Practical PostgreSQL Database Administration Commands]
     48* Root Password
     49{{{#!sh
     50$ sudo -u postgres psql postgres
     51ALTER USER postgres WITH PASSWORD '<password>';
     52\q
     53}}}
     54 * https://www.leaseweb.com/labs/2014/04/10-developer-tools-install-ubuntu-14-04/
     55* Drop all tables in a database
     56 * keywords: drop all tables from postgres database
     57 * This can be copyed into psql
     58{{{#!sql
     59DROP FUNCTION IF EXISTS remove_all();
     60
     61CREATE FUNCTION remove_all() RETURNS void AS $$
     62DECLARE
     63    rec RECORD;
     64    cmd text;
     65BEGIN
     66    cmd := '';
     67
     68    FOR rec IN SELECT
     69            'DROP SEQUENCE ' || quote_ident(n.nspname) || '.'
     70                || quote_ident(c.relname) || ' CASCADE;' AS name
     71        FROM
     72            pg_catalog.pg_class AS c
     73        LEFT JOIN
     74            pg_catalog.pg_namespace AS n
     75        ON
     76            n.oid = c.relnamespace
     77        WHERE
     78            relkind = 'S' AND
     79            n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
     80            pg_catalog.pg_table_is_visible(c.oid)
     81    LOOP
     82        cmd := cmd || rec.name;
     83    END LOOP;
     84
     85    FOR rec IN SELECT
     86            'DROP TABLE ' || quote_ident(n.nspname) || '.'
     87                || quote_ident(c.relname) || ' CASCADE;' AS name
     88        FROM
     89            pg_catalog.pg_class AS c
     90        LEFT JOIN
     91            pg_catalog.pg_namespace AS n
     92        ON
     93            n.oid = c.relnamespace WHERE relkind = 'r' AND
     94            n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
     95            pg_catalog.pg_table_is_visible(c.oid)
     96    LOOP
     97        cmd := cmd || rec.name;
     98    END LOOP;
     99
     100    FOR rec IN SELECT
     101            'DROP FUNCTION ' || quote_ident(ns.nspname) || '.'
     102                || quote_ident(proname) || '(' || oidvectortypes(proargtypes)
     103                || ');' AS name
     104        FROM
     105            pg_proc
     106        INNER JOIN
     107            pg_namespace ns
     108        ON
     109            (pg_proc.pronamespace = ns.oid)
     110        WHERE
     111            ns.nspname =
     112            'public'
     113        ORDER BY
     114            proname
     115    LOOP
     116        cmd := cmd || rec.name;
     117    END LOOP;
     118
     119    EXECUTE cmd;
     120    RETURN;
     121END;
     122$$ LANGUAGE plpgsql;
     123
     124SELECT remove_all();
     125}}}
     126http://stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql
     127 * http://stackoverflow.com/questions/20017552/delete-all-table-without-droping-database-in-postgres-in-django-dbshell-in-one-c
     128= Postgres for cache tables =
     129* nardberjean: dkg: may I ask you a question about postrgres and drupal cache tables?
     130* nardberjean: I read that posgres can be configured to be faster on less important data
     131* dkg: nardberjean: you can always ask questions here -- even though some of us might not know the answers ;)
     132* nardberjean: so I was asking me if that would apply to cache table
     133* dkg: yes, i recommend that cache tables be created as in-memory tables if you have enough RAM
     134* nardberjean: well I do not know it I can do that on mf machines
     135* nardberjean: as a member
     136* nardberjean: I have been told that the less RAM used the better on theses machines
     137* dkg: you might be interested in a few different points of documentation at a system level: [https://www.postgresql.org/docs/9.4/static/non-durability.html]
     138* dkg: in particular, look at [https://www.postgresql.org/docs/9.4/static/sql-createtable.html] and "unlogged"
     139* dkg: "the less RAM used the better" is always generally true but isn't very nuanced -- if you use less RAM by swapping everything to disk all the time to the point where no one can use the disk it seems worse to me.
     140* dkg: in my experience, most MF/PL machines are I/O constrained, not RAM constrained.
     141* nardberjean: well Non-Durable Settings would be good for I/O, and I could do it by myself, even if I feel the change should be made into Drupal code.
     142* nardberjean: for RAM tables, I do not know if it is already configured on mf machines, once I will have that info, I could try to move some small cache table to it...
     143* dkg: cool!  please report on support.mayfirst.org once you tried it out -- whether you make successful progress or otherwise, sorting this out is likely to be helpful to everyone on MF/PL. :)
     144* nardberjean: dkg: with d8 being very intense on cache, it makes it more an issue
     1452016-08-04