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.