> For the complete documentation index, see [llms.txt](https://docs.mosip.io/1.2.0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mosip.io/1.2.0/mosip-docs-1.1.5/build-and-deploy/other-installation-guides/steps-to-install-and-use-postgresql-version-10.2-on-rhel-7.5.md).

# Steps to Install and use PostgreSQL Version 10.2 on RHEL 7.5

Often simply Postgres, is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance. It can handle workloads ranging from small single-machine applications to large Internet-facing applications (or for data warehousing) with many concurrent users Postgresql Prerequisites On a Linux or Mac system, you must have superuser privileges to perform a PostgreSQL installation. To perform an installation on a Windows system, you must have administrator privileges.

## Steps to install Postgresql in RHEL-7.5

### Download and install PostgreSQL.

````
```
$ sudo yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm 
$ sudo  yum-config-manager --disable pgdg95
```
````

### Check the postgresql packages

````
```
$ sudo yum update 
$ sudo yum list postgresql*
```
````

### Installation command

````
```
$ sudo yum install postgresql10 postgresql10-server
$ sudo /usr/pgsql-10/bin/postgresql-10-setup initdb
$ sudo systemctl enable postgresql-10
```
````

### Postgresql service stop/start/restart command

````
```
$ sudo systemctl start postgresql-10
$ sudo systemctl status postgresql-10 
$ sudo systemctl stop postgresql-10
```
````

To changing default port 5432 to 9001 and connection + buffer size we need to edit the postgresql.conf file from below path PostgreSQL is running on default port 5432. you decide to change the default port, please ensure that your new port number does not conflict with any services running on that port.

## Steps to change the default port

### Open the file and modify the below changes

````
```
$ sudo vi /var/lib/pgsql/10/data/postgresql.conf
```
listen_addresses = '*'   (changed to * instead of local host )
port = 9001       ( uncomment port=5432 and change the port number 
Open the port 9001 from the VM 
````

### Use below command to open the port 9001 from RHEL 7.5 VM

````
```
$ sudo firewall-cmd --zone=public --add-port=9001/tcp --permanent
$ sudo firewall-cmd --reload
```
````

### To increase the buffer size and number of postgreSql connection same fine modify the below changes also

````
```
$ sudo vi /var/lib/pgsql/10/data/postgresql.conf 

unix_socket_directories = '/var/run/postgresql, /tmp' max_connections = 1000
shared_buffers = 2GB
```
````

### Start the service

````
```
$ sudo systemctl start postgresql-10
```
````

### To change the default password

#### Login to postgrsql

````
```
$ sudo su postgres
bash-4.2$ psql -p 9001
postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q
```
````

#### Restart the service:

````
```
$ sudo systemctl restart postgresql-10
```
````

It will ask new password to login to postgresql

**Example for sourcing the sql file form command line** `$ psql --username=postgres --host=<server ip> --port=9001 --dbname=postgres`

### Open the file

````
```
$ sudo vim /var/lib/pgsql/10/data/pg_hba.conf
```
````

\*\* Default lines are present in `pg_hab.conf` file\*\*

| TYPE  | DATABASE    | USER | ADDRESS      | METHOD |
| ----- | ----------- | ---- | ------------ | ------ |
| local | all         | all  |              | peer   |
| host  | all         | all  | 127.0.0.1/32 | ident  |
| host  | all         | all  | ::1/128      | ident  |
| local | replication | all  |              | peer   |
| host  | replication | all  | 127.0.0.1/32 | ident  |
| host  | replication | all  | ::1/128      | ident  |

\*\* Modify with below changes in file `/var/lib/pgsql/10/data/pg_hba.conf`\*\*

| TYPE  | DATABASE    | USER | ADDRESS      | METHOD           |
| ----- | ----------- | ---- | ------------ | ---------------- |
| local | all         | all  |              | md5              |
| host  | all         | all  | 127.0.0.1/32 | <p>ident<br></p> |
| host  | all         | all  | 0.0.0.0/0    | <p>md5<br></p>   |
| host  | all         | all  | ::1/128      | <p>ident<br></p> |
| local | replication | all  |              | <p>peer<br></p>  |
| host  | replication | all  | 127.0.0.1/32 | <p>ident<br></p> |
| host  | replication | all  | ::1/128      | <p>ident<br></p> |

```
$ sudo systemctl status postgresql-10
```

**Reference link:** <https://www.tecmint.com/install-postgresql-on-centos-rhel-fedora>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mosip.io/1.2.0/mosip-docs-1.1.5/build-and-deploy/other-installation-guides/steps-to-install-and-use-postgresql-version-10.2-on-rhel-7.5.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
