Steps for creating a Postgresql database in Linux: linuxpostgresql

Source: Internet
Author: User

Steps for creating a Postgresql database in Linux: linuxpostgresql

Preface

PostgreSQL (also called Postgres) is a free object-relational database server (Database Management System), which is released under a flexible BSD-style license. Because the default configuration is used to create a pgsql database, the root usage reaches 97%:

So I decided to re-create the database, and I forgot a lot of pitfalls. In order to avoid further forgetting, I decided to record the following and share it for your reference. Let's take a look at the detailed introduction.

The procedure is as follows:

Create a Data folder,/majestic12/pgsql/data

PGDATA = /majestic12/pgsql/dataset | grep PGDATA

Initialize db:

initdb -D /majestic12/pgsql/data

Start the database (running in the background)

postgres -D /majestic12/pgsql/data >logfile 2>&1 &

Create a database user (create a tdsadmin Super User and immediately give it a password)

createuser -P -s -e tdsadmin

Create a database (Create a database called TDS that belongs to tdsadmin)

createdb -O tdsadmin TDS

At this time, the creation is complete, but some exceptions may occur when accessing the database from the external.

For example, TCP/IP connection is not allowed, and:

Modify the configuration of the two files.

For postgresql. conf

#listen_address='127.0.0.1' =>listen_address = '*'

For pg_cmd.conf

#TYPE DATEBASE USER CIDR-ADDRESS METHODhost all  all 0.0.0.0/0 MD5

Restart the service after modification

 

Other information that may be required:

  • netstat -tulnView Current network port listening
  • ps -ef | grep postgres Check whether the PG process exists
  • cat postgresql.conf|grep listen Check whether the listening address is correct
  • psql postgres Enter the postgres command environment
  • ls -ltr Permission to view sub-files or directories
  • chkconfig postgresql-9.x on Set startup
  • chown -R postgres:postgres data dataFolder user group to ipvs
  • chmod -R 0700 data Change the permissions of all data files and sub-directories to rwx (0700)
  • The last digit of 0.0.0.0/0 is the subnet mask, 255.255.255.255 =>, 32.

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.

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.