Kamis, 25 Juni 2020

POSTGRESQL12.3-install centos7

1. Access Your Server

As with the previous method, first we have to access our server using SSH.

2. Download PostgreSQL Using Wget

Now we will download PostgreSQL version 9.6.3. Similarly, you can download any version. This can be done using the wget command.
wget https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/postgresql12-pltcl-12.3-5PGDG.rhel7.x86_64.rpm
This also requires RPM or RedHat Package manager along with EPEL (Extra Packages Enterprise Linux) repositories. This is required for additional PostgreSQL dependencies.

3. Install PosgreSQL on CentOS 7 with the Downloaded Package

This can be installed using the below command:
Hapus dulu yg lama
[root@middleware ~]# sudo yum -y remove postgres\*
yum install postgresql12-pltcl-12.3-5PGDG.rhel7.x86_64.rpm epel-release

4. Update Yum

Update yum so that your changes get reflected. Use the below command for this:
sudo yum update

5. Complete the PostgreSQL Install Process for CentOS 7

This completes our prerequisites for PostgreSQL installation. Next, we can install this using the below command:
sudo yum install postgresql12-server postgresql12-contrib
This completes our PostgreSQL installation.

6. Initialize the Database

Next, you can initialize the database using:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

7. Restart PostgreSQL

You can restart PostgreSQL using:
systemctl start postgresql-12

8. (Optional) Enable PostgreSQL Launch on Reboot

In case you want PostgreSQL to start at system reboot automatically then you can optionally use the below command:
systemctl enable postgresql-12

PostgreSQL Basic Setup

In Linux by default, a user named postgres is created once PostgreSQL is installed. You can change the user’s password with the following command:
sudo passwd postgres
You will be prompted to enter the new password twice.
Next, you can switch to the PostgreSQL prompt and change the password for the PostgreSQL postgres user using:
su - postgres
If you receive an error, you can set a valid shell on the user with the following command:
su --shell /bin/bash postgres
Afterwards, perform the same command:
su - postgres
To change the password, use the below command where you add your new password instead of the NewPassword:
psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'NewPassword';"
You can switch to the PostgreSQL client shell using:
psql postgres
Here you can check the list of available commands by typing \h. You can use \h followed by the command for which you need more information. To exit the environment you can type \q.
The createdb command lets you create new databases. Suppose we want to create a new database named testDB using the postgres Linux user. The command we would use would look like this:
createdb testDB
You can create a new role using the createuser command. Below is an example where we are creating a role named samplerole using the postgres Linux user.
createuser samplerole –pwprompt
Here you will be prompted to set a password for the user.
Optionally you can assign the ownership of our newly created database to a specific postgres user or role. This can be done with a command like this one:
createdb testDB -O samplerole
In the above command, replace samplerole with the role you want to use.
You can connect to this new database using the command bellow:
psql testDB
In case you want to use a specific user or role to log in, use the command as shown below:
psql testDB -U samplerole
This will prompt you to enter the password.
You can use \l or \list commands to show all the databases. To know the current database you’re using, you can use \c. In case you want more information about connections such as the socket, port, etc.  then you can use \conninfo.
You can also drop or delete a database using the dropdb command. However, remember to verify what you’re deleting before doing it. Deleted databases cannot be retrieved.
To delete a database, you can use:
dropdb testDB
PostgreSQL similar to other databases allows:

Tidak ada komentar:

Posting Komentar