Installation environment: Ubuntu 8.10
1. Enter the following command
$ Sudo apt-get install postgresql
Will prompt you whether to install the latest PostgreSQL database, enter Y, the system will automatically complete the installation
In this way, PostgreSQL. x. x is installed, and a default database cluster "main" is automatically created ";
Generate a database superuser named S. The password is blank. It is an operating system user (not logged on) and a database user (logged on ),
You can use the following command to change its password (for data security, you must change the password)
$ Sudo passwd postgres
Note: If you use the postgres account to log on to the database, use alter user Login s with password 'xxxxxx ';
If the password of the postgres account is modified, the passwd password is no longer valid for logging on to the database. The process is as follows:
Guo @ guo-laptop :~ $ Sudo su postgres # Switch to postgres private user
S @ guo-laptop:/home/guo $ psql S # log on to the postgres Database
Welcome to psql 8.3.7, PostgreSQL interactive text terminal.
Type \ copyright to display the release terms
\ H display description of SQL commands
\? Instructions on displaying pgsql commands
\ G or end with a semicolon (;) to execute the query
\ Q exit
Postgres = # alter user Login s with password 'xxxxxx'; # xxxxxx is the new Database PASSWORD
ALTER ROLE
Postgres = #/q
Postgres @ guo-laptop:/home/guo $ exit
Exit
Guo @ guo-laptop :~ $
2. add your own users and databases
$ Sudo su postgres # Switch to the postgres user to execute the following command:
$ Createuser-drSP sa # create a user that can create new users and databases, rather than superusers
Enter password for new role: # (Enter password 123, do not echo)
Enter again:# (Confirm Password 123, do not echo)
$ Createdb-O sa mydb # (Create a database mydb belonging to sa)
3. Use the following information to connect to the database:
Url = jdbc: postgresql: // localhost: 5432/mydb
User = sa
Passswd = 123
4. Access your database from other machines
4.1 Add the following lines to/etc/postgresql/8.3/main/pg_assist.conf:
Host All all 0.0.0.0/0 MD5 #0.0.0.0 indicates the starting address, and 0 indicates the number of binary IP addresses
# It is fixed, and the remaining bit is variable. The minimum value cannot be 0, and the maximum value cannot be 1.
#192.168.0.0/16 indicates 192.168.0.1 ~ 192.168.255.254
4.2 Add the following lines to/etc/PostgreSQL/8.3/main/PostgreSQL. conf:
Listen_addresses = '*'
4.3 restart the database
Sudo/etc/init. d/postgresql-8.3 restart
5. Recommended clients
Pgadmin3, squirrel SQL client (convenient for database migration)