equal
deleted
inserted
replaced
1 .. -*- coding: utf-8; -*- |
1 .. -*- coding: utf-8; -*- |
2 |
2 |
3 ========== |
3 ========== |
4 Postgre. |
4 Postgres |
5 ========== |
5 ========== |
6 .. contents:: |
6 .. contents:: |
7 :local: |
7 :local: |
8 |
8 |
9 Installing on Debian. |
9 Installing on Debian |
10 ===================== |
10 ==================== |
11 |
11 |
12 Install and create new user and database:: |
12 Install and create new user and database:: |
13 |
13 |
14 $ sudo apt-get install postgresql postgresql-client |
14 $ sudo apt-get install postgresql postgresql-client |
15 $ sudo su - postgres |
15 $ sudo su - postgres |
33 .. |
33 .. |
34 |
34 |
35 https://wiki.debian.org/PostgreSql |
35 https://wiki.debian.org/PostgreSql |
36 Debian wiki instructions. |
36 Debian wiki instructions. |
37 |
37 |
38 List databases, schemas and tables. |
38 List databases, schemas and tables |
39 =================================== |
39 ================================== |
40 |
40 |
41 Default database is ``postgres``. |
41 Default database is ``postgres``. |
42 |
42 |
43 To list databases and database locales:: |
43 To list databases and database locales:: |
44 |
44 |
62 To list all tables in the current database:: |
62 To list all tables in the current database:: |
63 |
63 |
64 => SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name; |
64 => SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name; |
65 => \dt |
65 => \dt |
66 |
66 |
|
67 List users:: |
|
68 |
|
69 \du |
|
70 |
67 Set default schema. |
71 Set default schema. |
68 =================== |
72 =================== |
69 :: |
73 :: |
70 |
74 |
71 set search_path to NAME; |
75 set search_path to NAME; |
|
76 set schema 'NAME'; |
72 |
77 |
73 Database, table, index size. |
78 Database, table, index size |
74 ============================ |
79 =========================== |
75 |
80 |
76 Database size:: |
81 Database size:: |
77 |
82 |
78 SELECT pg_database_size('geekdb'); -- in bytes |
83 SELECT pg_database_size('geekdb'); -- in bytes |
79 SELECT pg_size_pretty(pg_database_size('dbname')); |
84 SELECT pg_size_pretty(pg_database_size('dbname')); |
120 How to redirect the output of query to a file:: |
125 How to redirect the output of query to a file:: |
121 |
126 |
122 \o output_file |
127 \o output_file |
123 SELECT * FROM pg_class; |
128 SELECT * FROM pg_class; |
124 |
129 |
|
130 Switch database:: |
|
131 |
|
132 \connect DBNAME |
|
133 \c DBNAME |
|
134 |