Install postgresql in linux and configure remote graphical desktop connection.

Source: Internet
Author: User
Tags psql unix domain socket

Install postgresql in linux and configure remote graphical desktop connection.

I have recently used postgresql for projects that I have never touched before, so I have encountered some installation problems. Now I will record them.

1. Download postgresql9.4, my version is downloaded from the official website: http://download.csdn.net/detail/mu_wangyue/8679781 (if a friend wants to follow my steps, it is recommended to download this connection ). After the download, copy the postgresql-9.4.1-3-linux-x64.run to linux (xftp and other tools are available), I put it under the/usr/local/soft directory.


2. Modify the File Permission and add the execution permission. Command: chmod 755 postgresql-9.4.1-3-linux-x64.run


3. Add the installation directory before installation. Command: mkdir-p/usr/local/SQL/pgsql. Run the postgresql-9.4.1-3-linux-x64.run and enter the file name directly.


4. When selecting the installation directory, enter the directory created in the previous step (you can also use the default directory for installation), confirm the directory, and press Enter.


5. postgresql has a built-in highest-privilege user named postgres, which sets the user's password.


6. Set the port number


7. Set character sets


8. Enter the "Y" key to confirm database installation.


9. There may be a warning during the installation process. Ignore this and continue the installation.



After the above steps, the postgresql installation is complete, and the test is started below (some configurations will be explained in case of an error, so that you can understand the role of the configuration and find the error)

1. Switch to postgres and use the psql command in the installation directory to connect to the database. An error will be reported during connection:

Psql. bin: cocould not connect to server: There is no file or directory
Is the server running locally and accepting
Connections on Unix domain socket "/tmp/. s. PGSQL.5432 "?


We can find it in the/tem directory. The file ". s. PGSQL.5432" does not exist. There are two solutions: one is to restart (this involves other issues, not to mention), and the other is to add "-h ".


2. After the command "/usr/local/SQL/pgsql/bin/psql-h 127.0.0.1" is entered, the previous problem is solved, but a new problem occurs. Error:

Psql. bin: cocould not connect to server: Connection denied
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?



This problem occurs because the database service is not started.


3. Start the database and run the pg_ctl command in the bin directory. However, you must set the log and data Directories Before starting. Create the "pgdata" and "pglog" directories in the "/usr/local/SQL" directory.

Start command:/usr/local/SQL/pgsql/bin/pg_ctl start-D/usr/local/SQL/pgdata/-l/usr/local/SQL/pglog/

This means that pgdata is only a common directory, not a "database cluster" directory. To change the pgdata directory we created to the "database cluster" directory, use the initdb command in bin.

The cause of the above failure is that the directory for "database cluster" cannot be found, either specify the directory in-D mode or configure the environment variable PGDATA. The environment variables are configured here.

Modify/etc/profile and configure environment variables. "Vi/etc/profile ". Add the following configuration at the end of the file:

# Set postgresql environment
PG_HOME =/usr/local/SQL/pgsql
PGDATA =/usr/local/SQL/pgdata
PATH = $ PG_HOME/bin: $ PATH
Export PG_HOME PGDATA PATH

Restart linux to make the configuration take effect. Run the "initdb" command (you do not need to enter a directory because environment variables are configured) to report an error.

Initdb: cannot be run as root
Please log in (using, e.g., "su") as (unprivileged) user that will
Own the server process.

Cannot be started with the root user. Create a new user named "s" and replace the owner of the data directory with "postgres ".


Run "initdb" again. After the execution is successful, the pgdata directory contains the following content:


Run the command to start: pg_ctl-D/usr/local/SQL/pgdata/-l/usr/local/SQL/pglog/start


========================================================== ========================================================== ======================================

In fact, the installation is not so complex. The above is only written to show the errors so that you can know how to modify them.

Simple Installation Method

1. Create three directories before installation: pgsql, data, and log.

2. Specify the installation directory and data DIRECTORY during installation (not specified as the default)



3. After the installation is complete, the three directories are as follows (the system automatically creates the postgres user, and the data directory is also changed to the "database cluster" Directory ):



4. Run pg_ctl-D/usr/local/common/postgresql/data-l/usr/local/common/postgresql/log start to start the service. Some versions of postgresql may report errors:

"Sh:/usr/local/common/postgresql/log: Is a directory"

If this error occurs, create a new log file in the log directory, "touch server. log", and grant the write Permission to the S user. Otherwise, the error "Permission denied" will be reported.

After creating the file, run the following command: pg_ctl-D/usr/local/common/postgresql/data-l/usr/local/common/postgresql/log/server. log start can start the service.


5. After the startup is complete, remotely connect to the database psql-U postgres-d postgres-h 192.168.1.52-p 5432, or use navicat or other tools to connect to the database. An error message is displayed:

Psql: FATAL: no pg_hba.conf entry for host "192.168.1.41", user "qhzc", database "qhzc", SSL off

This is because the remote connection is rejected. You need to modify the pg_mirror.conf file. This file is located in the $ PGDATA directory and can be searched by the find command.


Note the following two files:

(1) In the postgresql. conf file, set listen_addresses = '*' to "*", not "localhost" (the default value is * after my installation *).


(2) Add the IP addresses that can be accessed under the IPV4 list in the pg_cmd.conf file, or directly set all IP addresses in a CIDR block to be accessible.


6. After the configuration is complete, use the local graphical interface for connection testing (taking navicat as an example)



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.