Install postgresql on ubuntu and how to use it

Source: Internet
Author: User
Tags psql postgres createdb
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.