About postgresql--Common operating instructions

Source: Internet
Author: User
Tags psql

This article is reproduced from http://blog.chinaunix.net/uid-22920230-id-3493064.html

Create a database

CREATE DATABASE Test with OWNER = postgres ENCODING = ' UTF8 ';

Enter the console method to execute the command under the installation purpose bin of PostgreSQL: Psql database name,
Cases:

/usr/local/pgsql/bin/psql MyDB

Specify host, user name, and database, such as:

View version: psql--version or SELECT version ();

View all databases:\l

View all databases (including detailed parameters):select * from Pg_database;

Select database:\c databasename

View all tables:\DT

To view the structure of a table:\d tablename

Exit Psql console:\q

To view the index of a table:

SELECT * from pg_indexes where tablename= ' log ';

To export a backup database:

Pg_dump-h localhost-u postgres databasename >/tmp/databasename.bak.yyyymmdd.sql


Import the Recovery database (the SQL file is the Pg_dump exported file, either the entire database, or just a single table, or just a structure, etc.):

Psql-h localhost-u postgres-d DatabaseName </tmp/databasename.bak.yyyymmdd.sql

Export data structure, mainly with the parameter-s:

To export a table:

Pg_dump-h localhost-u postgres-t tablename dbname > Test.sql

Export the structure of a table, also add parameter "-S":

To export data for a table, add the parameter "-a":

To view a sequence:

SELECT * from information_schema.sequences where Sequence_schema = ' public ';

To view the database size:

To view the size of a table:

About postgresql--Common operating instructions

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.