PostgreSQLInstallDebianEtch » History » Version 6
Lutz Suhrbier, 11/02/2007 06:24 PM
1 | 1 | Lutz Suhrbier | |
---|---|---|---|
2 | 6 | Lutz Suhrbier | # [[PostgreSQL]] Installation on Debian Etch |
3 | 1 | Lutz Suhrbier | |
4 | {{>toc}} |
||
5 | 2 | Lutz Suhrbier | |
6 | |||
7 | |||
8 | |||
9 | ## Installing [[PostgreSQL]] |
||
10 | |||
11 | Currently, [[PostgreSQL]] versions 7.5.22 and 8.1.9 are included within the stable release of Debian Etch. |
||
12 | |||
13 | |||
14 | This installs [[PostgreSQL]] 7.5.22 |
||
15 | |||
16 | ~~~ |
||
17 | # apt-get install postgresql |
||
18 | ~~~ |
||
19 | |||
20 | This installs [[PostgreSQL]] 8.1.9 |
||
21 | |||
22 | ~~~ |
||
23 | # apt-get install postgresql-8.1 |
||
24 | ~~~ |
||
25 | |||
26 | |||
27 | ### Installing the Python Interface to [[PostgreSQL]] |
||
28 | |||
29 | In order to use [[PostgreSQL]] within Python-scripts, the package [_python-psycopg2_](http://initd.org/projects/psycopg2) should be installed. |
||
30 | |||
31 | ~~~ |
||
32 | # apt-get install python-psycopg2 |
||
33 | ~~~ |
||
34 | |||
35 | |||
36 | 3 | Lutz Suhrbier | ### Installing the PHP Interface to [[PostgreSQL]] |
37 | 2 | Lutz Suhrbier | |
38 | 3 | Lutz Suhrbier | In order to use [[PostgreSQL]] within PHP-scripts, the package php5-pgsql must be installed. |
39 | 2 | Lutz Suhrbier | |
40 | ~~~ |
||
41 | # apt-get install php5-pgsql |
||
42 | ~~~ |
||
43 | |||
44 | |||
45 | ## Configuring [[PostgreSQL]] |
||
46 | |||
47 | |||
48 | |||
49 | 3 | Lutz Suhrbier | ### Administering [[PostgreSQL]] |
50 | 1 | Lutz Suhrbier | |
51 | 3 | Lutz Suhrbier | Initially, [[PostgreSQL]]'s administration account user name is _postgres_. This user account is also added to the system and is not password protected initially. There are at least two ways to administer postgreSQL |
52 | 1 | Lutz Suhrbier | |
53 | 3 | Lutz Suhrbier | 1. Login as system user _postgres_ |
54 | |||
55 | 2 | Lutz Suhrbier | ~~~ |
56 | 3 | Lutz Suhrbier | # su postgres |
57 | # psql |
||
58 | 1 | Lutz Suhrbier | ~~~ |
59 | 3 | Lutz Suhrbier | 1. Login as any other system user (e.g. root) |
60 | 1 | Lutz Suhrbier | |
61 | 3 | Lutz Suhrbier | ~~~ |
62 | # psql -h localhost -U postgres |
||
63 | ~~~ |
||
64 | You should now be logged onto the database shell environment. |
||
65 | 1 | Lutz Suhrbier | |
66 | |||
67 | 3 | Lutz Suhrbier | Since there is no password set, you should set a password for the postgres administrator accout first (in the shell). |
68 | 1 | Lutz Suhrbier | |
69 | 2 | Lutz Suhrbier | ~~~ |
70 | 3 | Lutz Suhrbier | ALTER USER postgres PASSWORD 'secret'; |
71 | ALTER ROLE |
||
72 | \q |
||
73 | 2 | Lutz Suhrbier | ~~~ |
74 | 1 | Lutz Suhrbier | |
75 | 5 | Lutz Suhrbier | The difference between the two login methods stated above, is that you don't have to enter a password using the first login method,if you want to login as the user you su'ed (e.g. postgres)! This may be useful within scripts. |
76 | 1 | Lutz Suhrbier | |
77 | |||
78 | |||
79 | 3 | Lutz Suhrbier | ### Create Users |
80 | 1 | Lutz Suhrbier | |
81 | 3 | Lutz Suhrbier | Users are also called roles in [[PostgreSQL]]. |
82 | 1 | Lutz Suhrbier | |
83 | 3 | Lutz Suhrbier | Select a login method and login to the shell. Then enter |
84 | |||
85 | 1 | Lutz Suhrbier | ~~~ |
86 | 3 | Lutz Suhrbier | CREATE USER user PASSWORD 'secret'; |
87 | \q |
||
88 | 1 | Lutz Suhrbier | ~~~ |
89 | |||
90 | 3 | Lutz Suhrbier | Alternatively, use the createdb command |
91 | 1 | Lutz Suhrbier | |
92 | 2 | Lutz Suhrbier | ~~~ |
93 | 3 | Lutz Suhrbier | # createuser user |
94 | 2 | Lutz Suhrbier | ~~~ |
95 | |||
96 | 3 | Lutz Suhrbier | |
97 | ### Create Databases |
||
98 | |||
99 | Usually, applications require an empty database for setup. An empty database (e.g. "_emptyDB_") can be created as follows. |
||
100 | |||
101 | Select a login method and login to the shell. Then, enter |
||
102 | |||
103 | 2 | Lutz Suhrbier | ~~~ |
104 | 3 | Lutz Suhrbier | CREATE DATABASE emptyDB OWNER user; |
105 | \q |
||
106 | 2 | Lutz Suhrbier | ~~~ |
107 | |||
108 | 3 | Lutz Suhrbier | Alternatively, use the createdb command |
109 | |||
110 | 2 | Lutz Suhrbier | ~~~ |
111 | 3 | Lutz Suhrbier | createdb -O user emptyDB |
112 | 2 | Lutz Suhrbier | ~~~ |
113 | |||
114 | |||
115 | 3 | Lutz Suhrbier | ### Granting Access Rights to a Database |
116 | |||
117 | If you want to assign all access rights on a database (e.g. _emptyDB_) to the user _user_, login to the shell and enter |
||
118 | |||
119 | 2 | Lutz Suhrbier | ~~~ |
120 | 3 | Lutz Suhrbier | GRANT ALL ON DATABASE emptyDB TO user; |
121 | \q |
||
122 | 1 | Lutz Suhrbier | ~~~ |
123 | 2 | Lutz Suhrbier | |
124 | |||
125 | ## Backup Databases |
||
126 | |||
127 | In order to backup databases or tables, use one of the following_mysqldump_ command lines. |
||
128 | |||
129 | ~~~ |
||
130 | # mysqldump [options] db_name [tables] |
||
131 | # mysqldump [options] --databases db_name1 [db_name2 db_name3...] |
||
132 | # mysqldump [options] --all-databases |
||
133 | ~~~ |
||
134 | |||
135 | For instance, if you want to backup the database exampleDB completely, the following command line stores the database _exampleDB_ into the SQL-script file named _exampleDB.sql_ |
||
136 | |||
137 | ~~~ |
||
138 | # mysqldump -u root --password='secret' exampleDB > exampleDB.sql |
||
139 | ~~~ |
||
140 | |||
141 | |||
142 | ## Import Databases |
||
143 | |||
144 | 4 | Lutz Suhrbier | Databases can be imported in [[PostgreSQL]] by executing SQL-script files, formerly generated by a database backup or manually. |
145 | 2 | Lutz Suhrbier | |
146 | The following commands imports the database from the file _exampleDB.sql_ into the _exampleDB_ database. |
||
147 | |||
148 | ~~~ |
||
149 | 4 | Lutz Suhrbier | # su postgres -c "psql -d exampleDB < exampleDB.sql" |
150 | 1 | Lutz Suhrbier | ~~~ |
151 | 4 | Lutz Suhrbier | ~~~ |
152 | # su postgres -c "psql -d exampleDB -f exampleDB.sql" |
||
153 | ~~~ |
||
154 | 2 | Lutz Suhrbier | |
155 | 1 | Lutz Suhrbier | |
156 | 2 | Lutz Suhrbier | ## Delete Databases |
157 | 1 | Lutz Suhrbier | |
158 | 4 | Lutz Suhrbier | To delete databases from [[PostgreSQL]], login to the shell and enter |
159 | 1 | Lutz Suhrbier | |
160 | ~~~ |
||
161 | 3 | Lutz Suhrbier | DROP DATABASE emptyDB; |
162 | \q |
||
163 | 1 | Lutz Suhrbier | ~~~ |