Adding a PostgreSQL to your Virtual Private Server allows you to organize and store your data. Here’s how you can do this on a Linux VPS:
1. Update your VPS
Ensure your package lists and the server is up-to-date by inputting the following commands:
1. Install PostgreSQL
Use the following command to install PostgreSQL:
1. Switch to the postgres account
As the initial account, you need to log in and connect with PostgreSQL. Do this with the following command:
1. Access a Postgres Session
Afterwards, you can access a Postgres session by using the command:
1. Exit out of the PostgreSQL prompt by typing
\`\`\` \q \`\`\`1. Create a New Role
First, create a new user by inputting `sudo adduser name_of_new_role`. You can switch over to the postgres account, and then create a new database user:
1. Create a New Database
Create a new Linux user first: `sudo adduser new_user`. Then, open up the PostgreSQL prompt: `sudo -u postgres createdb name_of_new_db`.
1. Open PostgreSQL and Set Up User Permissions
PostgreSQL will set up the necessary user permissions; type `psql` and then set a password for the new PostgreSQL user:
1. Edit the Authentication Method
Change the authentication method from ident to md5 by altering the PostgreSQL configuration file, usually located at `/etc/postgresql/9.5/main/pg_hba.conf`. Use this command to open up the file:
1. Restart PostgreSQL
\`\`\` sudo service postgresql restart \`\`\`Congratulations, you have installed and configured PostgreSQL on your VPS.