FEDORA22 Configuring the PostgreSQL database with RPM package installation

Source: Internet
Author: User
Tags psql



Strict intranet environment, no network connection, the newly installed Fedora 22 system, no other configuration.


Installation 1. Installation Environment:
    1. Operating system: Fedora 22
    2. Database: postgresql-9.4
    3. The installation process uses the root user
2. Install the package:
    1. postgresql94-libs-9.4.4-1pgdg.f22.x86_64.rpm
    2. postgresql94-9.4.4-1pgdg.f22.x86_64.rpm
    3. postgresql94-server-9.4.4-1pgdg.f22.x86_64.rpm

3. Install in Strict order:

rpm -ivh postgresql94-libs-9.4.4-1PGDG.f22.x86_64.rpm
rpm -ivh postgresql94-9.4.4-1PGDG.f22.x86_64.rpm
rpm -ivh postgresql94-server-9.4.4-1PGDG.f22.x86_64.rpm
4. After the installation is complete:
The default pg database installation directory is: /usr/pgsql-9.4
The default data file directory is: /var/lib/pgsql/9.4/data
5. Special note: installing with the rpm package is 2 steps less than installing directly with the tool yum:
The system commands provided by postgres: such as pg_ctl, psql, initdb, pg_dump, etc. are not automatically written into the system environment variables, so they cannot be used directly. Instead, you can use Directly used by all users.
Like yum installation, pg will create a new system user postgres, but there is no new postgres user home directory in the system / home directory. This directory is optional for users using the default data directory. But for the data directory to the postgres user's home directory, the user's home directory must be manually created.
6. Set the data file directory To set the data file directory of the database to the home directory of the postgres user, because the rpm installation is not automatically created, you need to manually create it. Create a directory
mkdir -p / home / postgres / data
Empowering directories
chown -R postgres: postgres / home / postgres
Configuration 1. Initialize the database service of the system Initialize the database cluster
sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb
Pay special attention to the initialization method of pgsql-9.2 and previous versions. The biggest difference between the two is whether there is a version information behind the command postgresql
sudo postgresql-setup initdb
Start the service By default, the postgresql service is disabled and started manually
sudo systemctl start /usr/pgsql-9.4/bin/postgresql-9.4.service
Also pay attention to psql-9.2 and previous versions of commands
sudo systemctl start postgresql.service
Set service startup
sudo systemctl enable /usr/pgsql-9.4/bin/postgresql-9.4.service
Also pay attention to psql-9.2 and previous versions of commands
sudo systemctl enable postgresql.service
Restart or reload To restart or reload the instance, use the command
sudo systemctl restart /usr/pgsql-9.4/bin/postgresql-9.4.service
sudo systemctl reload /usr/pgsql-9.4/bin/postgresql-9.4.service
Also pay attention to psql-9.2 and previous versions of commands
sudo systemctl restart postgresql.service
sudo systemctl reload postgresql.service
2. Initialize the database Switch users First switch from the current root user to the postgres user, because the database operation must use this user created by pg:
su postgres
Switch directories Don't mention that the commands provided by pg are not added to the environment variables. You need to add them manually or execute them in the command directory. Change to the bin directory of the pg database installation directory:
cd /usr/pgsql-9.4/bin
Initialization Note here is to initialize to the data directory we created in the previous step, instead of the default data directory of pg, all need to add the path
./initdb -D / home / postgres / data
After the initialization is successful, there will be a prompt:
2. Start the database Start in logfile mode. There are two tips for starting the database:
./pg_ctl -D / home / postgres / data -l logfile start
The command is correct, but it reports an error as soon as it starts: logfile does not have permissions. I was baffled: the data folder started was owned by the postgres user. I tried to go to / home / postgres first to build the logfile and then start the same error, but obviously the folders and files belong to the current user postgres. Later, after asking bigzhu, I realized that the logfile file did not specify a directory by default. It was created in the current directory, but the current directory /usr/pgsql-9.4/bin belongs to the root user (because the root was used during installation), so The current user postgres does not have permission to create a new logfile file in the root user's folder, so it fails to start. Specify the path of the logfile file and restart it with the command
./pg_ctl -D / home / postgres / data -l / home / postgres / logfile start
OK, the startup was successful. 3. Start error analysis Based on the above understanding of errors, then the other two methods should also be possible. How to start the yum installation If you use a package management tool similar to yum, then the environment variable has been added to the pg directory. In the / home / postgres directory, switch to the postgres user and use the command
pg_ctl -D / home / postgres / data -l logfile start
There must be no problem, the logfile file is created in the folder that currently belongs to the postgres user. Command full path start In the / home / postgres directory, switch to the postgres user, and then use the full path of the command
/usr/pgsql-9.4/bin/pg_ctl -D / home / postgres / data -l logfile start
There should be no problem, the logfile file is also created in the folder that currently belongs to the postgres user.
4. Open remote link pg database only open local link by default, you cannot remotely link by domain name or ip, modify configuration file
su root
vi /home/postgres/data/postgresql.conf
Note that the modified data directory is used for configuration, not the default installation directory of pg. modify
#listen_addresses = 'localhost'
In order to listen on all IPs, please note the comment symbol #
listen_addresses = '*'
5. Modify the access authentication with the command
su root
vi /home/postgres/data/pg_hba.conf
modify
# IPv4 local connections:
host all all 127.0.0.1/32 trust
Authenticate for md5
# IPv4 local connections:
host all all 0.0.0.0/0 md5
6. Restart the database
/usr/pgsql-9.4/bin/pg_ctl -D / home / postgres / data -l logfile restart

At this point, the database installation and configuration startup are all completed and can be used normally. Error addition When I use a remote application server to connect to this database, an error is reported:
psql: cannot connect to server: no route to host
        Whether the server is running on host "135.32.9.99" and is ready to accept on port
TCP / IP connection on 5432?
Test with a graphical interface tool: The current situation is:
The database is up and running normally, the port is 5432;
The remote link has been set up and the database has been restarted;
However, the remote link could not be connected. The last reason I found was that the built-in firewall of feodra 22 was turned on, the external links were blocked, and the firewall of feodra was turned off:
sudo systemctl stop firewalld.service
The link is successful and can be used.
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

fedora22 install and configure postgresql database with rpm package

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.