1. Installation
Apt-Get install postgresql-9.1
Default installation path:/etc/postgresql9.1
# Install pgadmin3 if you need an interface client
Sudo apt-Get install pgadmin3
2. Start
Sudo/etc/init. d/PostgreSQL start * Starting PostgreSQL 9.1 Database Server [OK]
3. Set Password
After the installation is complete, generate the super administrator Postgres. We need to change the password of Postgres user, otherwise we will not be able to use this database server.
Sudo su Postgres-C Psql template1alter user Postgres with password 'mypwd' sudo passwd Postgres # If you forget the password, you can use this to generate a new password.
4. Create a database
You cannot directly run sudo su ipvs-C createdb mydb. You need to log on to the sudo su ipvs and execute
Su ipvs # Switch user createdb mydb
5. Access Control
1. PostgreSQL does not have a simple way to manage users. You must Edit/Etc/Postgres/pg_hba.conf
And modify its default configuration (the security of the default configuration is very high)
After modification, You can execute pg_ctrl reload (or Postgres RELOAD). The modification takes effect directly without restarting.
2. EditThe port (5432 by default) and listening IP address (*) in/etc/Postgres. conf can connect to the database remotely.
User Management
Sudo su Postgres-C createuser-d-r-p myusersudo su Postgres-C createdb-O myuser mydb
The first command is to create a new user. This user has no permission to create a database (-D), and has no permission to create a new user (-R ). When creating a user, you will be prompted to enter the password.
The second command is to create a database'Mydb,'Myuser'As its owner.
You can also follow the steps below
Su postgrescreateuser-d-r-p myusercreatedb-O myuser mydbcreatedb-help # view help
Summary
1. Common commands
Createuser/dropuser createdb/dropdb
2. PostgreSQL interactive text Terminal
\ Copyright show release terms \ H show SQL command instructions \? Display the pgsql command description \ G or end with a semicolon (;) and run the query \ Q to exit
Reference: http://www.postgresql.org/download/linux/ubuntu/ # Installation
Http://wiki.ubuntu.org.cn/PostgreSQL # simple example
Http://www.postgresql.org/docs/9.1/interactive/index.html # official online documentation
Http://www.php100.com/manual/PostgreSQL8/ # Chinese documents