PostgreSQL Quick Start

Source: Internet
Author: User
Tags psql
PostgreSQL Quick Start

How to install and configure the PostgreSQL server in Ubuntu

Introduction

PostgreSQL is a powerful relational database management system, which is released in accordance with the BSD license [1. PostgreSQL contains many advanced features with good performance and good applicability.

PostgreSQL is bound to many programming languages, such as C, C ++,
Python, Java, PHP, Ruby, etc. It can operate many things, from simple web applications to a large database with millions of records.

Install

Run the following command to install PostgreSQL:

sudo apt-get install postgresql

Pgadmin III is a convenient PostgreSQL graphics client. It is suitable for beginners. You can run the following command on the terminal to install pgadmin III:

sudo apt-get install pgadmin3

You can also install these packages through the system> System Management> xinlide Package Manager.

Basic server settings

Start
Sudo/etc/init. d/postgresql-8.4 start (PostgreSQL installed in 10.04 is 8.4 by default, if it is 10.10, no version is required)
sudo /etc/init.d/postgresql-8.4 stop

Set Password

After the installation is complete, we need to change the password of Postgres user, otherwise we will not be able to use this database server. Run the Psql command as the Postgres user. Enter the following in the terminal:

sudo su postgres -c psql template1

At this time, a new prompt will appear. Enter the following two commands and replace them with the new password <*** password ***>:

ALTER USER postgres WITH PASSWORD ' <***password***> ';

Set the Postgres User Password
sudo passwd postgres

Then enter your password.

Create a database

Create the first database and name it "mydb". Enter:

su  postgres

Transferred to Postgres user.

An error will be reported when using this method.

sudo su postgres -c createdb mydb

After the user logs in to Postgres, execute

createdb mydb

Use the pgadmin iii gui client

To understand what PostgreSQL can do, you must first learn to use a GUI client and enter:

pgadmin3

You are now on the main interface of pgadmin III and click "add database connection" (in the upper left corner ). In the displayed dialog box, enter the address 127.0.0.1, server description, default database "mydb", and your password.

Through this graphic interface, you can create databases, tables, and other objects, query databases, add data, and execute SQL statements. Connect with pgadmin 3

Manage database servers

Manage Users and permissions

PostgreSQL does not have a simple way to manage users. You must Edit/etc/postgres/pg_hba.confAnd modify its default configuration (the security of the default configuration is very high), you want
postgresTo manage its users (not related to system users), you need to add the following lines:

8<-------------------------------------------# TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           METHOD# rezo localhost    all         all         10.0.0.0       255.255.255.0    password8<-------------------------------------------

It means to use your local network (replace 10.0.0.0/24 with your local network !), Postgres users can connect to the database using the traditional "User Name + password" method.

To create a database and create a user with all permissions for the database, run the following command:

sudo su postgres -c createuser -D -A -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 (-). 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.

This small example can meet most of your needs. For more information, see the help documentation or online documentation.

Further Exploration

If you are not familiar with the SQL language, you may want to study this powerful language in depth, although some simple PostgreSQL applications may not use this knowledge (such as a simple Django
Project ).

The PostgreSQL official website contains a lot of information about how to use this database.

Related Article

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.