Detailed steps for installing the Postgresql database in Ubuntu: ubuntupostgresql

Source: Internet
Author: User
Tags postgresql syntax psql postgres createdb

Detailed steps for installing the Postgresql database in Ubuntu: ubuntupostgresql

Introduction

As we all know, PostgreSQL is a free object-relational database server (Database Management System). It is very easy to install Postgresql In ubuntu. I will not talk about it much below, let's take a look at the detailed introduction.

The installation method is as follows:

1. Install the Postgresql server and client:

sudo apt-get install postgresql postgresql-client

2. After the installation is complete, Postgresql must be started. The following are some common operation commands:

# View sudo/etc/init. d/postgresql status # Start sudo/etc/init. d/postgresql start # Stop sudo/etc/init. d/postgresql stop # restart sudo/etc/init. d/postgresql restart

3. Create a new database user root and define it as a Super User:

sudo -u postgres createuser --superuser root

4. Set the root user password:

sudo -u postgres psql\password root\q

5. Create a database mydb:

sudo -u postgres createdb -O root test

6. Rename the database:

alter database mydb rename to mynewdb;

7. log on to the database:

psql -U root -d test -h 127.0.0.1 -p 5432

-U specifies the user,-d specifies the database,-h specifies the server, and-p specifies the port.

8. Common console commands:

  • \ H: view the explanations of SQL commands, such as \ h select.
  • \? : View the psql command list.
  • \ L: list all databases.
  • \ C [database_name]: connects to other databases.
  • \ D: list all tables of the current database.
  • \ D [table_name]: list the structure of a table.
  • \ Du: list all users.
  • \ E: Open the text editor.
  • \ Conninfo: lists information about the current database and connection.

9. database operations:

Database Operations are common SQL statements, but PostgreSQL syntax is available. For details, see the documentation.

Create a table:

create table users ( id serial primary key, username varchar(20), password varchar(20));

Insert data:

insert into users(username, password) values('admin', 'admin');

Query data

select * from users;

10. Install the graphic interface client PgAdmin. Who else needs to use SQL to create a table? After all, time is life:

sudo apt-get install pgadmin3

Note: Some of the content in this article comes from online materials. If there is any infringement, please let us know.

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.