In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
PostgreSQL compilation and installation
A brief introduction to PostgreSQL
PostgreSQL is currently the most powerful open source database, supporting rich data types and custom types, and it provides rich interfaces that can easily expand its functions.
Compared with other databases, PostgreSQL has the following advantages:
● PostgreSQL is currently the most powerful open source database
● is stable and reliable: PostgreSQL is the only open source database that can achieve zero data loss
● supports a wide range of languages: PostgreSQL supports a large number of mainstream development languages, including C, C++, Perl, Python, Java, PHP, etc.
The ● community is active: basically a new patch is released every three months, which means that BUG is known to be fixed soon
Compared with MySQL database, PostgreSQL database has the following advantages:
● is powerful: supports all mainstream multi-table join queries (such as Nest loop, hash join, etc.); has rich built-in functions and supports a large number of field types
● supports synchronous replication: starting from PostgreSQL9.1, synchronous replication is supported, and a highly available scheme with zero data loss can be achieved through replication between master and slave.
II. Installation and configuration of PostgreSQL
This installation uses source code compilation and installation, only for study and work, the default option is available, and the reader can choose the installation option.
1. Preparation before installation
● source code package
Postgresql-9.6.1.tar.gz, which can be downloaded with the following command
Wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz
● creates postgres users
PostgreSQL cannot be run as root, and its default running user is postgres
[root@a ~] # useradd postgres [root@a ~] # passwd postgres
● creates installation directory and data directory
[root@a] # mkdir-p / usr/local/pgsql/data
2. Start installation and configuration
Extract and install ●
Extract the source package, enter the decompression directory, and execute the configuration installation command
[root@a ~] # tar-xzf postgresql-9.6.1.tar.gz [root@a ~] # cd postgresql-9.6.1 [root@a postgresql-9.6.1] #. / configure-- prefix=/usr/local/pgsql [root@a postgresql-9.6.1] # make & & make install
If there is no error, we can configure it.
● related configuration
1) add environment variables
For convenience, we create a new file called pgsql.sh in the / etc/init.d/ directory, with the following contents, and make it effective immediately
[root@a ~] # more / etc/profile.d/pgsql.shexport PATH=$PATH:/usr/local/pgsql/bin [root@a ~] # source / etc/profile.d/pgsql.sh
2) change the data directory and installation directory owner and group to postgres
[root@a] # chown-R postgres.postgres / usr/local/pgsql
3) initialize the database
Switch to postgres user, initialize the postgresql database, and the corresponding database configuration file will be generated in the / usr/local/pgsql/data directory
[root@a] # su-postgres [postgres@a ~] $initdb-D / usr/local/pgsql/data# need to note that the / usr/local/pgsql/data directory here must be empty # now you can execute the following command to start the postgresql database service [postgres@a ~] $pg_ctl-D / usr/local/pgsql/data-l logfile start
4) modify the configuration file
Now that our database can only be accessed by local users, we need to modify the configuration file to make it accessible to remote machines.
[postgres@a ~] $cd / usr/local/pgsql/data [postgres@a data] $vi postgresql.conf# add all listening addresses at # listen_addresses = 'localhost', that is, add listen_addresses =' *'[postgres@a data] $vi pg_hba.conf# change the IP address of host to the address of the IP network segment to be accessed, and change the authentication method to md
The screenshot after modification is as follows:
5) copy the service startup script to the / etc/init.d/ directory, and add the pgsqld service
Switch to root user, copy contrib/startscripts/linux to / etc/init.d/pgsqld in the decompressed directory, and simply modify it to grant execution permission.
[root@a postgresql-9.6.1] # cp contrib/start-scripts/linux / etc/init.d/pgsqld [root@a postgresql-9.6.1] # vi / etc/init.d/pgsqld## check whether this option corresponds to the data directory you set. If not, modify # # this option defaults to PGDATA= "/ usr/local/pgsql/data" # to add execution permissions And add services to boot # chmod + x / etc/init.d/pgsqld restart service # service pgsqld restart# add to boot # chkconfig-- add pgsqld# chkconfig pgsqld on
At this point, the PostgreSQL installation and configuration is complete, we can switch to the postgres user, execute the psql command to enter the postgres interactive mode, and carry out the relevant database operations.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.