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)05/31 Report--
This article introduces the relevant knowledge of "the installation of postgresql database and the method of modifying the path of data files". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
One: postgresql database installation: two methods 1, installation package installation. 2jinyum installation
1.yum installation.
Download the postgresql image with your own operating system. It then shows how to install and start postgresql using yum, as shown in the following figure:
Install the repository RPM:
Yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-1.noarch.rpm
Install the client packages:
Yum install postgresql10
Optionally install the server packages:
Yum install postgresql10-server
Optionally initialize the database and enable automatic start:
Service postgresql-10 initdb
Chkconfig postgresql-10 on
Service postgresql-10 start
2)。 Install using an image.
1. Download the latest version of postgresql: http://www.postgresql.org/ftp/source/
Or select the corresponding os system and the postgresql version you want on the official website, and then click to download the enterprise version:
Https://www.enterprisedb.com/download-postgresql-binaries
Then select the desired version
2. Decompress the file:
Tar zxvf postgresql-8.3.7.tar.gz
Cd postgresql-8.3.7
3. Compile and specify the path where postgresql is installed
. / configure-- prefix=/usr/local/pgsql
4. Compile:
Make
5. Install:
Make install
6. Create user groups and users:
Groupadd postgres
Useradd-g postgres postgres
7. Create a database file storage directory and grant permissions to postgres:
Mkdir / usr/local/pgsql/data
Cd / usr/local/pgsql
Chown postgres.postgres data
8. Edit ~ / .bash_profile file
# vi ~ / .bash_profile
Set the following environment variables
Export PGHOME=/usr/local/pgsql
Export PGDATA=/usr/local/pgsql/data
9. Initialize the database directory:
Switch users
Su-postgresql
Initialization data-D specifies the file path of the database created by initialization
/ usr/local/pgsql/bin/initdb-D / usr/local/pgsql/data
Two: start, log in, and exit
If you need to specify an environment variable, do the following:
Postgres@lgr-pc:~$ vi .bash _ profile
Add the following:
Export PGDATA=/usr/local/pgsql/data
Export PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
That is, specify the directory of pgdata and bin, which can be specified according to your actual directory.
After editing the environment variable file, run the following command to make the environment variable take effect:
Postgres@lgr-pc:~$. .bash _ profile
After setting the environment variables, run the following command to start the server:
Postgres@lgr-pc:~$ pg_ctl start
Second login server
When the database is installed, we will have a system user, a database user, and their default name is: postgres
1. If the environment variable for the bin directory is not set, then
Postgres@lgr-pc:~$ / usr/local/pgsql/bin/psql
By default, you can log in to the postgres library, but you can also add the name of the library after the psql so that you can log in to the specified library. If you log in to the test library:
Postgres@lgr-pc:~$ / usr/local/pgsql/bin/psql test
If you set the environment variable of the bin directory as I did, then
Postgres@lgr-pc:~$ psql
The default is to log in to the postgres library. Similarly, we can specify the database name and log in to the specified library.
Postgres@lgr-pc:~$ psql test
Three logins
It's easy to log out. We can run\ Q or ctrl+d.
Postgres=#\ Q
4. Shut down the database server
Close:
Postgres@lgr-pc:~$ pg_ctl stop
Restart:
Postgres@lgr-pc:~$ pg_ctl restart
3. PGSQL changes the storage path of the data:
1) after the database software is installed, when initializing the database, you can specify the default file path of the database created during initialization
Specify the location and encoding of the database, and initialize the database:
/ usr/local/pgsql/bin/initdb-D / usr/local/pgsql/data
After initialization, modify the configuration file postgresql.conf to the modified data file path to ensure that the future data files are also under this path.
2) if it has been initialized, then modify the path of the data file, as follows:
Find the configuration file to see where the original data storage path is.
Sudo find /-name postgresql.conf
Usually at / etc/postgresql/9.6/main/postgresql.conf
Stop the PGSQL.
Sudo service postgresql stop
Copy the original data path to the new path
Sudo cp-rf / var/lib/postgresql/9.6/main/ / data/postgresql/
Set users and permissions
Sudo chown-R postgres:postgres / data/postgresql/
Sudo chmod 700 / data/postgresql/
Change the data storage path of the configuration file to the new
Sudo vim / etc/postgresql/9.6/main/postgresql.conf
Data_directory='/data/postgresql/datafile'
Just start it again.
Sudo service postgresql start
Quickly find the number of lines in the configuration file where data_directory is located:
Bogon:root@/usr/pgsql-10/bin > cat / var/lib/pgsql/10/data/postgresql.conf | grep-n data_directory
41:#data_directory = 'ConfigDir' # use data in another directory
After modification, you can use the psql command "show data_directory" to view the current data directory
Postgres=# show data_directory
Data_directory
-
/ var/lib/pgsql/10/data
(1 row)
This is the end of the content of "the installation of postgresql database and how to modify the path of data files". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.