Project

General

Profile

PostgreSQL » History » Version 1

Marc Dequènes, 2018-05-02 18:03

1 1 Marc Dequènes
h1. PostgreSQL
2
3
h2. Authentication
4
5
3 methods:
6
* access via UNIX socket for all accounts
7
* access via local role database for local accounts
8
* access via PAM for non-local accounts
9
10
h3. Local Accounts
11
12
These are accounts needed for system services (user services should use secondary accounts defined in the LDAP instead).
13
14
Creation:
15
* create a normal role with login right (and probably inherit right too)
16
* add the role in the special ''local-roles'' role members
17
18
Beware all roles directly or *indirectly* members of the *local-roles* role (indirect members == members of members of members...) will have to authenticate via their local hash and not via PAM!
19
20
h3. PAM Accounts
21
22
Creation:
23
* create a normal role with login right (and probably inherit right too) with no password
24
25
That's all !
26
27
h3. Managing Team Work
28
29
Create:
30
* create a normal role without login right and password
31
* add user roles as member of this role
32
* give this role rights to the parts the team is working on
33
34
Beware not to use this role for login, or you'll probably end-up adding it to the *local-roles* and all PAM users not able to login anymore (see remark in the *Local Accounts* chapter)!
35
36
h2. Storage sizes
37
38
h3. Databases sizes
39
40
<pre>
41
SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database;
42
</pre>
43
44
h3. Tables sizes in current database
45
46
<pre>
47
 SELECT nspname, relname,
48
 pg_size_pretty(tablesize+indexsize+toastsize+toastindexsize) AS totalsize
49
 FROM
50
 (SELECT ns.nspname, cl.relname, pg_relation_size(cl.oid) AS tablesize,
51
 COALESCE((SELECT SUM(pg_relation_size(indexrelid))::bigint
52
 FROM pg_index WHERE cl.oid=indrelid), 0) AS indexsize,
53
 CASE WHEN reltoastrelid=0 THEN 0
54
 ELSE pg_relation_size(reltoastrelid)
55
 END AS toastsize,
56
 CASE WHEN reltoastrelid=0 THEN 0
57
 ELSE pg_relation_size((SELECT reltoastidxid FROM pg_class ct
58
 WHERE ct.oid = cl.reltoastrelid))
59
 END AS toastindexsize
60
 FROM pg_class cl, pg_namespace ns
61
 WHERE cl.relnamespace = ns.oid
62
 AND ns.nspname NOT IN ('pg_catalog', 'information_schema')
63
 AND cl.relname IN
64
 (SELECT table_name FROM information_schema.tables
65
 WHERE table_type = 'BASE TABLE')) ss
66
 ORDER BY tablesize+indexsize+toastsize+toastindexsize DESC;
67
</pre>
68
69
h2. PostgreSQL interrupted recovery
70
71
If you got something like this in your logs:
72
<pre>
73
2011-07-15 16:23:12 CEST LOG:  database system was interrupted while in recovery at 2008-03-21 00:02:22 CET
74
2011-07-15 16:23:12 CEST HINT:  This probably means that some data is corrupted and you will have to use the last backup for recovery.
75
2011-07-15 16:23:12 CEST LOG:  database system was not properly shut down; automatic recovery in progress
76
2011-07-15 16:23:12 CEST LOG:  consistent recovery state reached at 28/55780068
77
2011-07-15 16:23:12 CEST LOG:  redo starts at 28/55780068
78
2011-07-15 16:23:12 CEST WARNING:  specified item offset is too large
79
2011-07-15 16:23:12 CEST CONTEXT:  xlog redo insert: rel 1663/16387/17911; tid 76/212
80
2011-07-15 16:23:12 CEST PANIC:  btree_insert_redo: failed to add item
81
2011-07-15 16:23:12 CEST CONTEXT:  xlog redo insert: rel 1663/16387/17911; tid 76/212
82
2011-07-15 16:23:12 CEST LOG:  startup process (PID 2981) was terminated by signal 6: Aborted
83
2011-07-15 16:23:12 CEST LOG:  aborting startup due to startup process failure
84
</pre>
85
86
If you don't care about loosing uncommited data:
87
<pre>
88
su - postgres
89
/usr/lib/postgresql/9.0/bin/pg_resetxlog -f 9.0/main/
90
</pre>
91
Running first without -f can give hints about the situation.
92
93
Dumping, reiniting, and reloading data is recommended.