{"id":22133,"date":"2026-07-03T05:27:00","date_gmt":"2026-07-02T23:57:00","guid":{"rendered":"https:\/\/www.youstable.com\/blog\/?p=22133"},"modified":"2026-06-27T14:21:27","modified_gmt":"2026-06-27T08:51:27","slug":"how-to-set-up-postgresql-on-a-vps","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/how-to-set-up-postgresql-on-a-vps\/","title":{"rendered":"How to Set Up PostgreSQL on a VPS: Step-by-Step Guide 2026"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Setting up PostgreSQL on a VPS is one of those tasks that looks complex at first but becomes straightforward once you know the exact steps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have set it up dozens of times, and in this guide, I am walking you through every single step, nothing skipped, nothing assumed. Whether you are a developer building your first app or a sysadmin managing production servers, you will find everything you need right here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have also added proper screenshots for every step so you can follow along exactly the way I have done it. By the time you finish reading this, your PostgreSQL database will be live, secured, and ready to use on your VPS.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Please Note:<\/strong><br>This guide uses Ubuntu 24.04 LTS as the operating system on the VPS. All commands are tested and up to date as of 2026. You will need root or sudo access to your VPS to follow these steps.Screenshots are included at every major step to help you verify your progress.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"what-is-postgresql-and-why-should-you-use-it-on-a-vps\">What Is PostgreSQL and Why Should You Use It on a VPS?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL is one of the most powerful open-source relational database management systems in the world.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It has been around for over 35 years and is trusted by companies like Apple, Instagram, and Spotify to manage massive amounts of data reliably.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike <strong><a href=\"https:\/\/www.youstable.com\/blog\/best-shared-hosting-in-india\/\">shared hosting<\/a><\/strong> environments where resources are limited and configurations are restricted, a VPS gives you full control over your PostgreSQL setup, your memory allocation, your security rules, and your performance tuning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"why-postgresql-over-other-databases\">Why PostgreSQL Over Other Databases?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You might wonder why PostgreSQL instead of <a href=\"https:\/\/www.youstable.com\/blog\/create-mysql-on-linux\/\">MySQL<\/a> or <a href=\"https:\/\/www.youstable.com\/blog\/what-is-mariadb-on-linux-server\/\">MariaDB<\/a>. Here is the honest answer: PostgreSQL handles complex queries better, supports advanced data types like JSON and arrays natively, and enforces data integrity more strictly.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are building anything beyond a simple blog, PostgreSQL is the database you want powering it.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Full ACID compliance for safe and reliable transactions<\/li>\n\n\n\n<li>Native JSON support for flexible data structures<\/li>\n\n\n\n<li>Advanced indexing for faster query performance<\/li>\n\n\n\n<li>Active community and regular security updates<\/li>\n\n\n\n<li>Free and open source with no licensing costs<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"why-is-a-vps-the-right-thing-to-setup-postgresql\">Why is a VPS the Right Thing to Setup PostgreSQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Running PostgreSQL on a VPS means you control everything. You choose how much RAM to allocate, which port to use, who can connect remotely, and how backups are scheduled.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Shared hosting blocks most of this.&nbsp;<\/strong><\/td><td><strong>A VPS unlocks the full potential of PostgreSQL for your projects.<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"how-to-setup-postgresql-on-a-vps\">How to Setup PostgreSQL on a VPS?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Just like a dad helps his baby girl walk, the same manner I am going to tell you step by step how to setup PostgreSQL on a VPS. I have not missed anything at all and the entire procedure mentioned below is <strong>100% tested<\/strong>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>To make your setup process much easier, I\u2019ve added screenshots of the terminal and also added the commands in the boxes so that if the screenshots aren\u2019t clear, you can simply copy paste the commands and continue with the process.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-1-order-a-vps-from-youstable\">Step 1: Order a VPS from YouStable<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before you can set up PostgreSQL, you need a VPS. I recommend YouStable for this.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YouStable offers reliable <strong><a href=\"https:\/\/www.youstable.com\/vps-hosting\">VPS hosting<\/a><\/strong> with SSD storage, full root access, and a clean Ubuntu installation, which is exactly what you need for this setup. The pricing is affordable and the servers spin up fast.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Recommended VPS Provider<\/strong><br><strong>Visit YouStable VPS Hosting:<\/strong> <a href=\"https:\/\/www.youstable.com\/vps-hosting\">https:\/\/www.youstable.com\/vps-hosting<\/a> &gt;&gt; Choose a plan with at least 1 GB RAM and 10 GB SSD storage for a basic PostgreSQL setupFor production workloads, I recommend 2 GB RAM or more.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Now, how to order your VPS on YouStable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these steps exactly and you will have your VPS ready in a few minutes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to <strong><a href=\"https:\/\/www.youstable.com\/vps-hosting\">YouStable VPS Hosting<\/a><\/strong> in your browser.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/www.youstable.com\/vps-hosting\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1876\" height=\"673\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-31.png\" alt=\"YouStable VPS Hosting\" class=\"wp-image-22138\"\/><\/a><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Browse the available VPS plans. For PostgreSQL hosting, pick a plan with at least 1 GB RAM and Ubuntu 24.04 as the operating system &gt;&gt; Click the \u2018Get Started&#8217; button on the plan you want.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/www.youstable.com\/vps-hosting\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1382\" height=\"705\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-32.png\" alt=\"VPS Hosting Plans &amp; Pricing\" class=\"wp-image-22139\"\/><\/a><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On the configuration page, select &#8216;Ubuntu 24.04 LTS&#8217; as your operating system from the dropdown.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1046\" height=\"506\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-29.png\" alt=\"Operating System\" class=\"wp-image-22136\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose your billing cycle &gt;&gt; Pick a bigger billing cycle to save more (Get Flat 65% OFF) &gt;&gt; Proceed to checkout.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1057\" height=\"257\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-27.png\" alt=\"Choose Billing Cycle\" class=\"wp-image-22134\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create your YouStable account or log in if you already have one.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1480\" height=\"606\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-30.png\" alt=\"\" class=\"wp-image-22137\"><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Complete the payment. YouStable supports multiple payment options &gt;&gt; Once payment is done, your VPS will be provisioned within a few minutes.<\/li>\n\n\n\n<li>You will receive an email with your VPS IP address, root username, and root password. Save these.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"966\" height=\"441\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-28.png\" alt=\"\" class=\"wp-image-22135\"><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>After your VPS is provisioned, log into your YouStable dashboard and navigate to the VPS section. You will see your server listed with its IP address and status.&nbsp;<br>Take note of this IP, you will need it throughout this guide.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-2-connect-to-your-vps-via-ssh\">Step 2: Connect to Your VPS via SSH<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now that your VPS is ready, you need to connect to it. You do this through SSH, which is a secure way to access your server remotely from your computer. The connection gives you full command-line control over the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>So, how to connect from Windows?&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On Windows, you can use a tool called PuTTY or the built-in Windows Terminal. I recommend the Windows Terminal since it comes pre-installed on Windows 10 and 11.<\/li>\n\n\n\n<li>Open your Windows Terminal or Command Prompt and run this command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh root@YOUR_VPS_IP_ADDRESS<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace YOUR_VPS_IP_ADDRESS with the actual IP address from your YouStable welcome email. When prompted, type yes to accept the connection, then enter your root password.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"719\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-41.png\" alt=\"\" class=\"wp-image-22148\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once connected, you will see a terminal prompt that looks like: root@your-server-name:~#<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This confirms you have root access to the VPS and are ready to begin the installation.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Security Note<\/strong><br>Using root directly is fine for setup, but after setup, I recommend creating a non-root sudo user for daily use.I will show you how to do this in the security configuration section later in this guide.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-3-update-your-vps-before-installing-anything\">Step 3: Update Your VPS Before Installing Anything<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before you install PostgreSQL, update your server&#8217;s package list.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This makes sure you get the latest available version of every package and avoids dependency issues during installation. Skipping this step is one of the most common reasons people run into errors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Run these two commands one after the other:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command fetches the latest package information from Ubuntu&#8217;s servers.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command upgrades all installed packages to their latest versions<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The -y flag automatically confirms the upgrade without asking you each time. This process might take a few minutes depending on how many packages need updating.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"957\" height=\"555\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-33.png\" alt=\"\" class=\"wp-image-22140\"><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>You will see a long list of packages being updated scrolling through your terminal. Wait until you see the command prompt return.<br>That means the upgrade is complete.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-4-install-postgresql-on-your-vps\">Step 4: Install PostgreSQL on Your VPS<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now comes the main part.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You are going to install PostgreSQL using the official PostgreSQL APT repository.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I recommend this method over the default Ubuntu repository because it gives you the latest stable version of PostgreSQL with up-to-date security patches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Add the Official PostgreSQL APT Repository<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run these commands in order to add the official PostgreSQL repository to your server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y curl ca-certificatessudo install -d \/usr\/share\/postgresql-common\/pgdgsudo curl -o \/usr\/share\/postgresql-common\/pgdg\/apt.postgresql.org.asc --fail \\https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1164\" height=\"530\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-37.png\" alt=\"\" class=\"wp-image-22143\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>&nbsp;Now run the automated repository setup script:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y postgresql-commonsudo \/usr\/share\/postgresql-common\/pgdg\/apt.postgresql.org.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When this script runs, it will ask you to confirm adding the repository &gt;&gt; Press Enter to accept &gt;&gt; After it finishes, your server now has access to the official PostgreSQL packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install PostgreSQL<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now install the latest stable version of PostgreSQL. As of 2026, PostgreSQL 17 is the current stable release:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt updatesudo apt install -y postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please Note:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Running &#8216;<strong>sudo apt install -y postgresql<\/strong>&#8216; installs the latest version available in the PGDG repository.<\/li>\n\n\n\n<li>If you want to install a specific version like PostgreSQL 17, you can run: <strong>sudo apt install -y postgresql-17<\/strong><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1073\" height=\"675\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-43.png\" alt=\"\" class=\"wp-image-22150\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Both commands work fine for this guide.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You will see PostgreSQL and its dependencies being downloaded and installed.<\/li>\n\n\n\n<li>The installation automatically starts the PostgreSQL service when done.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-5-verify-that-postgresql-is-running\">Step 5: Verify That PostgreSQL Is Running<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, PostgreSQL starts automatically. You need to verify that it is actually running before you move forward. A service that is installed but not running will cause confusing errors later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Run this command to check the status:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see an output that shows &#8216;active (running)&#8217; in green. That means PostgreSQL is up and accepting connections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you see &#8216;inactive&#8217; or &#8216;failed&#8217;, run: <strong>sudo systemctl start postgresql<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then check the status again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also confirm the PostgreSQL port is listening by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -tlnp | grep 5432<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see port 5432 listed, which is PostgreSQL&#8217;s default port. If you see it, the database is ready.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1077\" height=\"648\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-40.png\" alt=\"\" class=\"wp-image-22146\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Enable PostgreSQL to Start Automatically on Reboot. By default, PostgreSQL should start on boot, but it is a good habit to make sure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This ensures PostgreSQL starts automatically every time your VPS reboots, so you never have to worry about it being down after a server restart.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-6-access-the-postgresql-command-line\">Step 6: Access the PostgreSQL Command Line<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL uses a special system user called &#8216;postgres&#8217; that gets created automatically during installation. To access the PostgreSQL command line, you switch to this user first and then open the PostgreSQL shell.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Switch to the PostgreSQL User. And to do that, run this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -i -u postgres<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your terminal prompt will change.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You are now operating as the postgres system user. Notice how the prompt now shows postgres@ instead of root@.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the PostgreSQL Shell (psql) &gt;&gt; Now open the PostgreSQL interactive terminal by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>psql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>You will see a prompt that looks like this:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres=#<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1065\" height=\"646\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-34.png\" alt=\"\" class=\"wp-image-22141\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You are now inside PostgreSQL &gt;&gt; You can run database commands from here. To exit the shell at any time, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\\q<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your terminal should now show: postgres=#&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the psql prompt. Everything you type here is a PostgreSQL command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>SQL commands end with a semicolon (;). psql commands start with a backslash (\\).<\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-7-create-a-new-postgresql-database-and-user\">Step 7: Create a New PostgreSQL Database and User<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The default postgres superuser is fine for administration, but for your actual applications, you should always create a dedicated database and a dedicated user with limited permissions.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a clean way to organize your projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a New Database<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, make sure you are inside the psql shell (<em>you should see postgres=#<\/em>). Then run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE myappdb;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace myappdb with whatever name you want for your database. You will see &#8216;<strong>CREATE DATABASE<\/strong>&#8216; in the output, which confirms it worked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a New Database User<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now create a user that your application will use to connect to this database:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>CREATE USER myappuser WITH ENCRYPTED PASSWORD &#8216;YourStrongPassword123!&#8217;;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please Note<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace &#8216;YourStrongPassword123!&#8217; with a unique password.<\/li>\n\n\n\n<li>Use a mix of letters &amp; special characters.<\/li>\n\n\n\n<li>Never use simple passwords like &#8216;123456&#8217;.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1065\" height=\"654\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-36.png\" alt=\"\" class=\"wp-image-22144\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Grant Permissions to the New User<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Give your new user full access to the new database:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>GRANT ALL PRIVILEGES ON DATABASE <\/strong><strong>myappdb <\/strong><strong>TO <\/strong><strong>myappuser<\/strong><strong>;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now your user myappuser has full control over myappdb. This user cannot access any other database unless you explicitly grant that permission.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Verify the Database Was Created<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To see a list of all databases on the server, run <strong>\\l<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should see myappdb in the list alongside the default postgres and template databases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The \\l command lists all databases with their owner and encoding. You should see myappdb listed with myappuser as owner after granting privileges.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Type<strong> \\q<\/strong> to exit psql when done.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-8-configure-postgresql-for-remote-access\">Step 8: Configure PostgreSQL for Remote Access<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, PostgreSQL only accepts connections from the server itself (localhost).&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your application runs on a different server, or if you want to connect to the database using a tool like pgAdmin from your laptop, you need to configure PostgreSQL to allow remote connections.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please follow these steps carefully.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Edit the PostgreSQL Configuration File<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, exit the psql shell if you are still inside it by running \\q.&nbsp;<\/li>\n\n\n\n<li>Then go back to your root or sudo user &gt;&gt; Find the PostgreSQL configuration file and open it:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/postgresql\/*\/main\/postgresql.conf<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Inside this file, find the line that says:<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>#listen_addresses = 'localhost'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Change it to:<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>listen_addresses = '*'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The asterisk (*) tells PostgreSQL to listen on all available network interfaces &gt;&gt; Save the file by pressing Ctrl+X, then Y, then Enter.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1074\" height=\"714\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-44.png\" alt=\"\" class=\"wp-image-22151\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Edit the Client Authentication Configuration<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Now open the <em>pg_hba.conf<\/em> file which controls who can connect and how:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/postgresql\/*\/main\/pg_hba.conf<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scroll to the bottom of this file and add this line:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>host all &nbsp; &nbsp; &nbsp; &nbsp; all &nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0\/0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scram-sha-256<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Disclaimer<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The line above allows connections from ANY IP address. This is fine for initial setup and testing.<\/li>\n\n\n\n<li>For a production server, replace &#8216;0.0.0.0\/0&#8217; with your specific IP address.<\/li>\n\n\n\n<li>Allowing all IPs on a production server without a firewall is a security risk.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Restart PostgreSQL to Apply Changes<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After editing both files, restart PostgreSQL for the changes to take effect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Then verify it is still running:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please note this too:&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After restart, the status should still show &#8216;active (running)&#8217;.<\/li>\n\n\n\n<li>If it shows an error, check your edits in postgresql.conf and pg_hba.conf for typos.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-9-configure-the-firewall-to-allow-postgresql\">Step 9: Configure the Firewall to Allow PostgreSQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Even with PostgreSQL configured to listen on all interfaces, your VPS firewall may still block incoming connections on port 5432. You need to open this port.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On Ubuntu, the default firewall is UFW (Uncomplicated Firewall).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Check If UFW Is Active<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If UFW is active and port 5432 is not listed, you need to add it. If UFW is inactive, you can skip to the next section, though I recommend enabling it at first.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1067\" height=\"713\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-39.png\" alt=\"\" class=\"wp-image-22147\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Allow PostgreSQL Through the Firewall<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run this command to allow connections on PostgreSQL&#8217;s port:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 5432\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For better security, allow connections only from a specific IP address:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow from YOUR_IP_ADDRESS to any port 5432<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace YOUR_IP_ADDRESS with the IP of the machine you are connecting from.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Enable UFW If It Is Not Active<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To enable UFW and ensure SSH access is not blocked:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow OpenSSHsudo ufw enable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please also make sure that:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always allow OpenSSH before enabling UFW.<\/li>\n\n\n\n<li>If you enable UFW without allowing SSH first, you will lock yourself out of the server.<\/li>\n\n\n\n<li>If that happens, use the VPS emergency console in your YouStable dashboard to regain access.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-10-test-the-remote-connection\">Step 10: Test the Remote Connection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now test that you can connect to PostgreSQL from your local machine or another server. This confirms that everything is set up correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Connect Using the psql Client<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From your local machine (not the VPS), run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>psql -h YOUR_VPS_IP -U myappuser -d myappdb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will be prompted for the password you set earlier &gt;&gt; Enter it and press Enter &gt;&gt; If you see the psql prompt, your remote connection is working.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Test Using a Sample Query<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once connected, run a quick test to make sure the database responds correctly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT version();<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1101\" height=\"553\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-35.png\" alt=\"\" class=\"wp-image-22142\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This returns the PostgreSQL version string, confirming the connection and the database are both working.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You should see output like: PostgreSQL 17.x on x86_64-pc-linux-gnu&#8230;<\/li>\n\n\n\n<li>This confirms your remote connection is working and PostgreSQL is responding to queries.&nbsp;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-11-secure-your-postgresql-installation\"><strong>Step 11: Secure Your PostgreSQL Installation<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I have told in so many places that security is never optional.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A PostgreSQL database exposed to the internet without proper hardening is a serious risk. Here are the essential security steps you should take right after setting up PostgreSQL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set a Strong Password for the PostgreSQL Superuser<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The default postgres superuser has no password set &gt;&gt; Fix this immediately &gt;&gt; Connect to psql:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -i -u postgrespsql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Then set a password:<\/strong>&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>ALTER USER postgres WITH ENCRYPTED PASSWORD &#8216;YourSuperSecurePassword!&#8217;;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"985\" height=\"697\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-38.png\" alt=\"\" class=\"wp-image-22145\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a Non-Root Sudo User for Daily VPS Access<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Stop using root for everything. Create a regular user with sudo privileges:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adduser yournameusermod -aG sudo yourname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">From now on, log in as this user instead of root.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Revoke Unnecessary Permissions<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to restrict what your application user can do, remove permissions you do not need:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>REVOKE ALL ON DATABASE myappdb FROM PUBLIC;<\/strong><strong>GRANT CONNECT ON DATABASE myappdb TO myappuser;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please Note<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The REVOKE ALL FROM PUBLIC command prevents other users from connecting to your database by default.<\/li>\n\n\n\n<li>Then the GRANT CONNECT command gives only your specific user access.<\/li>\n\n\n\n<li>This is a clean permission model for most applications.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-12-basic-postgresql-commands-you-will-use-every-day\">Step 12: Basic PostgreSQL Commands You Will Use Every Day<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now that PostgreSQL is running and secured, here are the commands you will reach for most often. I have organized these so you can refer back to this section whenever you need a quick reminder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Database Management Commands<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">\\l<\/td><td class=\"has-text-align-center\" data-align=\"center\">List all databases<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\\c myappdb<\/td><td class=\"has-text-align-center\" data-align=\"center\">Connect to a database<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\\dt<\/td><td class=\"has-text-align-center\" data-align=\"center\">List all tables in current database<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\\du&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/td><td class=\"has-text-align-center\" data-align=\"center\">List all users and roles<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">CREATE DATABASE newdb;&nbsp;&nbsp;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Create a new database<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">DROP DATABASE olddb;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Delete a database<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>User Management Commands<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CREATE USER username WITH ENCRYPTED PASSWORD &#8216;password&#8217;;<\/li>\n\n\n\n<li>DROP USER username;<\/li>\n\n\n\n<li>GRANT ALL PRIVILEGES ON DATABASE dbname TO username;<\/li>\n\n\n\n<li>REVOKE ALL PRIVILEGES ON DATABASE dbname FROM username;<\/li>\n\n\n\n<li>ALTER USER username WITH PASSWORD &#8216;newpassword&#8217;;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Service Management Commands<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">sudo systemctl start postgresql<\/td><td class=\"has-text-align-center\" data-align=\"center\">Start the service<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">sudo systemctl stop postgresql<\/td><td class=\"has-text-align-center\" data-align=\"center\">Stop the service<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">sudo systemctl restart postgresql<\/td><td class=\"has-text-align-center\" data-align=\"center\">Restart the service<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">sudo systemctl status postgresql<\/td><td class=\"has-text-align-center\" data-align=\"center\">Check service status<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">sudo systemctl reload postgresql<\/td><td class=\"has-text-align-center\" data-align=\"center\">Reload configuration without restart<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"step-13-how-to-backup-and-restore-a-postgresql-database\">Step 13: How to Backup and Restore a PostgreSQL Database<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Never run a production database without a backup plan. PostgreSQL gives you a built-in tool called pg_dump for creating backups. Here is how to use it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a Database Backup<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run this command to create a full backup of your database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u postgres pg_dump myappdb &gt; \/home\/yourname\/myappdb_backup.sql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates a .sql file containing all the data and schema for myappdb. You can store this file locally, upload it to cloud storage, or automate it with a cron job.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1092\" height=\"714\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2026\/06\/image-42.png\" alt=\"\" class=\"wp-image-22149\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Restore a Database from Backup<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>To restore the database from a backup file:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u postgres psql myappdb &lt; \/home\/yourname\/myappdb_backup.sql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Please Note<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The database you are restoring into must already exist before running the restore command.<\/li>\n\n\n\n<li>If it does not exist, create it first: CREATE DATABASE myappdb;<\/li>\n\n\n\n<li>For automated backups, set up a cron job that runs pg_dump every night and saves to a secure location.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"troubleshooting-common-postgresql-issues\">Troubleshooting Common PostgreSQL Issues<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Even with perfect setup steps, things sometimes go sideways. Here are the most common issues and how to fix them fast.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"error-connection-refused-on-port-5432\">Error: Connection Refused on Port 5432<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This usually means PostgreSQL is not running or is not listening on the expected port. Check the service status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Then check if port 5432 is open:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -tlnp | grep 5432<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the port is not listed, check your postgresql.conf file and make sure listen_addresses = &#8216;*&#8217; is set and saved correctly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"error-fatal-password-authentication-failed\">Error: FATAL: password authentication failed<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You entered the wrong password. Reset it by connecting locally as postgres:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>sudo -i -u postgres<\/strong><strong>psql<\/strong><strong>ALTER USER myappuser WITH ENCRYPTED PASSWORD &#8216;NewPassword123!&#8217;;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"error-fatal-no-pg_hba-conf-entry-for-host\">Error: FATAL: no pg_hba.conf entry for host<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your pg_hba.conf does not have an entry for the IP address you are connecting from. Open the file and add the correct entry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/postgresql\/*\/main\/pg_hba.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add a line for your IP or use 0.0.0.0\/0 for testing, then restart PostgreSQL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"postgresql-service-fails-to-start\"><strong>PostgreSQL Service Fails to Start<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check the logs for the exact error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -u postgresql --no-pager | tail -20<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Read the last 20 lines of the log. The error message will tell you exactly what is wrong, whether it is a config file typo, a port conflict, or a permissions issue.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"my-verdict-for-this-guide\">My Verdict For This Guide<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you follow each and every command, follow all my instructions word to word, then in that case, you\u2019ll have a fully working PostgreSQL database running on your VPS.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>You:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>installed it from the official repository,&nbsp;<\/li>\n\n\n\n<li>configured remote access,&nbsp;<\/li>\n\n\n\n<li>set up the firewall,&nbsp;<\/li>\n\n\n\n<li>created a dedicated database and user,&nbsp;<\/li>\n\n\n\n<li>secured the installation,&nbsp;<\/li>\n\n\n\n<li>and learned how to back up your data.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I have personally verified and tested every step in this guide<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most important thing I want you to take away from this guide is that PostgreSQL on a VPS is not complicated once you follow the right steps. Your database is now production-ready. If you run into any issues, the troubleshooting section has you covered for the most common problems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Always keep your VPS and PostgreSQL updated.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run sudo apt update and sudo apt upgrade regularly to make sure you have the latest security patches. A well-maintained server is a secure server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start with <strong><a href=\"https:\/\/www.youstable.com\/\">YouStable<\/a><\/strong> for your VPS and you will have a solid foundation from the very first day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up PostgreSQL on a VPS is one of those tasks that looks complex at first but becomes straightforward once [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":22161,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"iawp_total_views":89,"footnotes":""},"categories":[1136,2261,350],"tags":[],"class_list":["post-22133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-kb-databases","category-knowledgebase"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/22133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=22133"}],"version-history":[{"count":0,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/22133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/22161"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=22133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=22133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=22133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}