<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Guantai Jp</title>
    <description>The latest articles on Forem by Guantai Jp (@guantai_jp_5560b141c5c9c7).</description>
    <link>https://forem.com/guantai_jp_5560b141c5c9c7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3397883%2F1abb17d4-2c6f-40f5-8d2e-5d584937fdea.jpg</url>
      <title>Forem: Guantai Jp</title>
      <link>https://forem.com/guantai_jp_5560b141c5c9c7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/guantai_jp_5560b141c5c9c7"/>
    <language>en</language>
    <item>
      <title>How to Install and Set Up PostgreSQL on a Linux Server</title>
      <dc:creator>Guantai Jp</dc:creator>
      <pubDate>Sun, 03 Aug 2025 15:58:27 +0000</pubDate>
      <link>https://forem.com/guantai_jp_5560b141c5c9c7/how-to-install-and-set-up-postgresql-on-a-linux-server-aka</link>
      <guid>https://forem.com/guantai_jp_5560b141c5c9c7/how-to-install-and-set-up-postgresql-on-a-linux-server-aka</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
PostgreSQL is one of the most trusted and widely used open-source relational database systems. It's reliable, powerful, and a great choice whether you're building a small personal project or a production-grade system.&lt;/p&gt;

&lt;p&gt;In this guide, I’ll walk you through how to install and set up PostgreSQL on a Linux server. Whether your server is in the cloud, running on a virtual machine, or simply your own laptop, these steps will help you get PostgreSQL up and running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is a Linux Server?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Linux server is just a computer running a Linux-based operating system, used to host apps, services, or databases like PostgreSQL. It can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A cloud server (like AWS, DigitalOcean, or Azure)&lt;/li&gt;
&lt;li&gt;A physical machine (e.g., your laptop running Ubuntu)&lt;/li&gt;
&lt;li&gt;A virtual machine (VM) using software like VirtualBox or WSL on Windows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No matter the setup, the goal is the same: to get PostgreSQL working as your database engine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Update the Server&lt;/strong&gt;&lt;br&gt;
Before installing anything, it’s good practice to make sure the system is up to date. Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Install PostgreSQL&lt;/strong&gt;&lt;br&gt;
Now install PostgreSQL and some useful extras:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install postgresql postgresql-contrib -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, check the version to confirm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Start and Enable PostgreSQL&lt;/strong&gt;&lt;br&gt;
Make sure PostgreSQL is running and will start automatically on reboot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start postgresql
sudo systemctl enable postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the status with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Log Into PostgreSQL&lt;/strong&gt;&lt;br&gt;
PostgreSQL comes with a default user called postgres. To use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -i -u postgres
psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re now inside the PostgreSQL terminal. To exit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Set a Password for the Default User&lt;/strong&gt;&lt;br&gt;
Still as the postgres user, set a secure password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER USER postgres WITH PASSWORD 'your_secure_password';
\q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Create Your Own Database and User&lt;/strong&gt;&lt;br&gt;
Let’s create a new database and user that your application can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE my_database;
CREATE USER my_user WITH ENCRYPTED PASSWORD 'my_password';
GRANT ALL PRIVILEGES ON DATABASE my_database TO my_user;
\q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can replace my_database and my_user with names that match your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional: Enable Remote Access&lt;/strong&gt;&lt;br&gt;
If you plan to connect to PostgreSQL from another machine (like with DBeaver or pgAdmin), you’ll need to allow external connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Edit PostgreSQL settings:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/postgresql/14/main/postgresql.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#listen_addresses = 'localhost'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listen_addresses = '*'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Allow remote users:&lt;/strong&gt;&lt;br&gt;
Edit this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/postgresql/14/main/pg_hba.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this at the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;host    all             all             0.0.0.0/0               md5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Restart the PostgreSQL service:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optional: Open Port 5432 (Firewall)&lt;/strong&gt;&lt;br&gt;
If you have UFW enabled, allow connections to PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow 5432/tcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optional: Connect Using a GUI (Like DBeaver or pgAdmin)&lt;/strong&gt;&lt;br&gt;
You can use desktop tools like DBeaver, pgAdmin, or DataGrip to connect to your Linux server.&lt;/p&gt;

&lt;p&gt;You’ll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host: Your server's IP address&lt;/li&gt;
&lt;li&gt;Port: 5432&lt;/li&gt;
&lt;li&gt;Database: &lt;code&gt;my_database&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;User: &lt;code&gt;my_user&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Password: The one you set earlier&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is helpful if you prefer a visual interface instead of typing SQL in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrapping Up&lt;/strong&gt;&lt;br&gt;
That’s it! You now have PostgreSQL installed and configured on your Linux server. You can create databases, connect to them remotely, and start using them in your projects.&lt;/p&gt;

&lt;p&gt;Whether you’re using this for a local test setup or a full cloud deployment, PostgreSQL is a great foundation to build on.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>postgressql</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
