This article mainly introduces how to install and use postgresql in ubuntu. if you need it, refer to the following tag: Ubuntu
Install components
Client installation
Sudo apt-get install postgresql-client
Server Installation
Copy codeThe code is as follows:
Sudo apt-get install postgresql-contrib
Obtains the list of Installing PostGIS, procedural extensions ages, client interfaces, and other plug-ins.
Copy codeThe code is as follows:
Apt-cache search postgres
Ruby PG gem installation requires Native Extension
First install the corresponding package
Copy codeThe code is as follows:
Sudo apt-get install libpq-dev
Locate pg_config
Copy codeThe code is as follows:
Sudo find/-name pg_config
Install pg gem
Copy codeThe code is as follows:
Gem install pg -- with-pg-config =/usr/bin/pg_config
Server Configuration
Set postgres user, use postgres user to log on and change password
Copy codeThe code is as follows:
Sudo-u postgres psql postgres
Set password for IPVs users
Copy codeThe code is as follows:
\ Password S
Create a new database
Copy codeThe code is as follows:
Sudo-u postgres createdb mydb
Advanced Server settings
Create User
Copy codeThe code is as follows:
Sudo-u postgres createuser -- superuser $ USER
Sudo-u postgres psql
Postgres = # \ password $ USER
Manage users and permissions
Edit the/etc/postgresql/current/main/postgresql. conf file to listen to other networks.
Copy codeThe code is as follows:
Listen_addresses = '*'
Create a new user named tesdb and the user's database named testdb.
Copy codeThe code is as follows:
Sudo-u postgres createuser-D-A-P testdb
Sudo-u postgres createdb-O testdb
Edit the/etc/postgresql/current/main/pg_assist.conf file to allow the testdb user to remotely connect to the testdb database.
Copy codeThe code is as follows:
Host testdb 0.0.0.0/0 md5
Reload configuration
Copy codeThe code is as follows:
Sudo/etc/init. d/postgresql reload
Restart database
Copy codeThe code is as follows:
Sudo/etc/init. d/postgresql restart