Learn how to install PostgreSQL on Ubuntu Server to harness advanced database management capabilities. This comprehensive guide from EcoStack Cloud provides step-by-step instructions for setting up PostgreSQL efficiently and securely on your server.
ubuntudatabasepostgresql
Large
VPS
3
vCPU
12 GB
Memory
120 GB
NVMe Disk
6144 GB
Traffic
29.90€
/month
* Up to 6 vCPU, 36GB RAM, 360GB NVMe Disk Space and 1Gbit/s Network Speed
#### Step 1: Update Your System
Ensure your Ubuntu Server is up-to-date before installing PostgreSQL.
```bash
sudo apt update
sudo apt upgrade -y
```
#### Step 2: Install PostgreSQL
Install PostgreSQL from the official Ubuntu repositories.
```bash
sudo apt install postgresql postgresql-contrib -y
```
#### Step 3: Verify Installation
Check if PostgreSQL is installed and running.
```bash
sudo systemctl status postgresql
```
#### Step 4: Access PostgreSQL Shell
Log in to the PostgreSQL interactive terminal.
```bash
sudo -i -u postgres
psql
```
#### Step 5: Set PostgreSQL Password
Set a password for the default PostgreSQL user (postgres).
```sql
\password postgres
```
#### Step 6: Basic PostgreSQL Commands
Explore basic PostgreSQL commands within the psql shell.
- Create a new database:
```sql
CREATE DATABASE mydatabase;
```
- Switch to a specific database:
```sql
\c mydatabase;
```
- Create a new user:
```sql
CREATE USER myuser WITH PASSWORD 'mypassword';
```
- Grant privileges to a user:
```sql
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
```
Congratulations! You have successfully installed PostgreSQL on your Ubuntu Server. For more tutorials and cloud solutions, visit EcoStack Cloud.
---