banner



How To Open Postgresql Database In Windows

PostgreSQL

Setting up a local PostgreSQL database

Overview

This page explains how to install and configure a PostgreSQL database server and the psql command line client. This guide will encompass how to install and set up these components on your computer for local admission.

This guide will cover the following platforms:

  • Setting up PostgreSQL on Windows
  • Setting up PostgreSQL on macOS
  • Setting upwards PostgreSQL on Linux
    • Debian and Ubuntu
    • CentOS and Fedora

Navigate to the sections that match the platforms yous volition be working with.

RELATED ON PRISMA.IO

Once you have a PostgreSQL database, you can use Prisma Client to manage it from within your JavaScript or TypeScript applications. Attempt our PostgreSQL getting started guide to get started.

Setting up PostgreSQL on Windows

The PostgreSQL projection provides a native Windows installer to install and configure your database.

Visit the PostgreSQL Windows installation page to discover a link to the installer. Click Download the installer at the kickoff of the folio:

PostgreSQL initial download page

On the folio that follows, in the Windows x86-64 or Windows x86-32 columns (depending on your computer'south architecture), cull the PostgreSQL version you lot'd like to install:

PostgreSQL available versions

Click Download on your chosen version and salve the file to a convenient location.

Once the download completes, double click on the file to run the installer (you may take to ostend that you wish to let the program to make changes to your computer):

PostgreSQL installer greeting

Click Adjacent on the initial folio to begin configuring your installation.

On the next page, cull your installation directory:

PostgreSQL installation directory

Click Next to accept the default location.

The side by side page allows you to cull which components you wish to install. Y'all demand the PostgreSQL Server and Command Line Tools selected at a minimum:

PostgreSQL choose components

Click Side by side to continue.

Now, cull the location where the database data files will exist stored:

PostgreSQL data directory

Click Adjacent to accept the default location.

Next, select and confirm an authoritative countersign for the PostgreSQL superuser (called postgres):

PostgreSQL set password

Click Next when you are finished.

Choose the port that the server will listen to:

PostgreSQL set port

Click Side by side to accept the default 5432 port.

Now, choice the locale that your database will use:

PostgreSQL locale

Click Adjacent to use the default locale of your computer.

The configuration portion of the installation is at present complete. You can review a summary of the choices you've made:

PostgreSQL installation summary

If everything looks correct, click Side by side.

Finally, PostgreSQL is ready to exist installed:

PostgreSQL ready to install

Click Next to begin the installation procedure.

Once the installation is complete, you can verify the installation using the psql command line tool.

In your start carte, type psql and click on the tool to launch the plan. Yous will be prompted to enter the connection details that you wish to use.

Running psql client

Press Enter to have the default choices given in the square brackets. The terminal prompt will be for the password for the postgres user that yous configured during setup.

Upon successfully authenticating, y'all will be dropped into an interactive psql session with your database.

When you are finished, go out the session by typing:

          

Setting up PostgreSQL on macOS

The PostgreSQL project provides a native macOS installer to install and configure your database.

Visit the PostgreSQL macOS installation page to notice a link to the installer. Click Download the installer at the start of the Interactive Installer by EnterpriseDB department:

PostgreSQL initial download page

On the page that follows, in the Mac Bone X column, choose the PostgreSQL version y'all'd like to install:

PostgreSQL available versions

Click Download on your chosen version and salvage the file to a user-friendly location.

In one case the download completes, find the PostgreSQL installer DMG in the Downloads binder. Double click on the downloaded DMG file to mount the installer annal:

PostgreSQL DMG file

In the mounted archive, click on the PostgreSQL installer parcel (you may exist prompted to confirm that you want the package to be able to make changes to your reckoner):

PostgreSQL installer package

The PostgreSQL installer will open to the welcome screen:

PostgreSQL installer welcome

Click Side by side on the initial page to begin configuring your installation.

On the side by side folio, choose your installation directory:

PostgreSQL installation directory

Click Next to take the default location.

The adjacent page allows you to choose which components you wish to install. You need the PostgreSQL Server and Command Line Tools selected at a minimum:

PostgreSQL choose components

Click Next to continue.

At present, choose the location where the database data files will be stored:

PostgreSQL data directory

Click Next to accept the default location.

On the next page, select and confirm an authoritative countersign for the PostgreSQL superuser (called postgres):

PostgreSQL set password

Click Next when y'all are finished.

The post-obit page lets you choose the port that the server volition listen to:

PostgreSQL set port

Click Next to have the default 5432 port.

Now, pick the locale that your database will employ:

PostgreSQL locale

Click Adjacent to use the default locale of your reckoner.

The configuration portion of the installation is now consummate. Yous tin review a summary of the choices you've made:

PostgreSQL installation summary

If everything looks correct, click Next.

PostgreSQL is ready to be installed:

PostgreSQL ready to install

Click Side by side to begin the installation process.

The installer will confirm completion when the procedure completes:

PostgreSQL installation complete

Now that PostgreSQL is installed, yous can verify the installation using the psql control line tool. While this customer is installed, we need to change our terminal's PATH variable to access it hands.

Open a new final window to begin. First, find the PostgreSQL bin directory past typing:

              
                                      

ls -d /Library/PostgreSQL/*/bin

The response will be the directory of your PostgreSQL bin directory. For example:

              
                                      

/Library/PostgreSQL/12/bin

At present that yous know the directory to utilise, edit the /etc/paths file by typing:

            

You lot will exist prompted for your computer's administrative password to proceed:

PostgreSQL open paths file

Add the path to bin directory that you found to the lesser of the file:

PostgreSQL edit paths file

When you are finished, save and close the file by typing CTL-X, Y, and hitting ENTER.

To use the new PATH settings, open a new final window. In the new window, type:

            

Y'all volition exist prompted for the postgres user's administrative password that you set during the PostgreSQL configuration process:

PostgreSQL psql authentication

Upon successfully authenticating, yous will be dropped into an interactive psql session with your database.

To exit the session when you are finished, type:

          

Setting up PostgreSQL on Linux

Installation methods differ depending on the Linux distribution you lot are using. Follow the department below that matches your Linux distribution.

  • Debian and Ubuntu
    • Install using Debian or Ubuntu's default repositories
    • Install using the PostgreSQL project'south Debian and Ubuntu repositories
  • CentOS and Fedora
    • Install using CentOS or Fedora's default repositories
    • Install using the PostgreSQL project'due south CentOS and Fedora repositories

Debian and Ubuntu

You can either choose to use the version of PostgreSQL bachelor in your distribution'due south default repositories or use repositories provided by the PostgreSQL project. Packages in the default repository are tested to work with all other software provided for your distribution, merely may be older. Packages from the PostgreSQL project will be more than upwardly-to-date only may require extra configuration.

  • Install using Debian or Ubuntu'southward default repositories
  • Install using the PostgreSQL projection's Debian and Ubuntu repositories

Install using Debian or Ubuntu'south default repositories

Both Ubuntu and Debian provide versions of PostgreSQL server every bit packages inside their default repositories. The PostgreSQL version may exist older than those found on the PostgreSQL website, but this is the simplest style to install on these distributions.

To install PostgreSQL server, update your computer'southward local package cache with the latest set of packages. Later, install the postgresql package:

                  
                                              

sudo apt update

sudo apt install postgresql

By default, PostgreSQL is configured to utilize peer authentication, which allows users to log in if their operating system user name matches a PostgreSQL internal name.

The installation process created an operating organization user called postgres to friction match the postgres database authoritative account. To log into PostgreSQL with the psql customer, employ sudo to run the command as the postgres user:

                

When yous are finished, y'all can exit the psql session by typing:

              

Install using the PostgreSQL project'due south Debian and Ubuntu repositories

If you need a more upward-to-date version of PostgreSQL, you tin apply the repositories maintained by the PostgreSQL projection instead of those provided past your Linux distribution.

Offset, add a new repository definition to your system by typing:

                  
                                              

echo "deb http://apt.postgresql.org/pub/repos/apt/ $(. /etc/os-release; echo $VERSION_CODENAME)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.listing

Next, add together the PostgreSQL package signing key to apt then that it trusts the packages in the new repository:

                  
                                              

wget --tranquility -O - https://world wide web.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-central add -

With the repository fix, you tin can update your local bundle index so install PostgreSQL by typing:

                  
                                              

sudo apt update

sudo apt install postgresql

By default, PostgreSQL is configured to apply peer authentication, which allows users to log in if their operating arrangement user proper noun matches a PostgreSQL internal name.

The installation process created an operating arrangement user called postgres to match the postgres database administrative business relationship. To log into PostgreSQL with the psql client, employ sudo to run the control equally the postgres user:

                

When you lot are finished, you tin can exit the psql session by typing:

              

CentOS and Fedora

You can either choose to use the version of PostgreSQL available in your distribution's default repositories or utilize repositories provided by the PostgreSQL project. Packages in the default repository are tested to work with all other software provided for your distribution, only may be older. Packages from the PostgreSQL projection will exist more than up-to-date but may require extra configuration.

  • Install using CentOS or Fedora's default repositories
  • Install using the PostgreSQL project's CentOS and Fedora repositories

Install using CentOS or Fedora's default repositories

Both CentOS and Fedora provide versions of PostgreSQL server as packages within their default repositories. The PostgreSQL version may be older than those found on the PostgreSQL website, simply this is the simplest way to install on these distributions.

To install PostgreSQL server, utilize your distribution's package director to install the mysql-server package:

For CentOS utilise the yum package manager:

                  
                                              

sudo yum install postgresql-server

For Fedora utilise the dnf parcel director:

                  
                                              

sudo dnf install postgresql-server

Once the MySQL package is installed, initialize the database by typing:

                  
                                              

sudo postgresql-setup initdb

Afterward, start up the service past typing:

                  
                                              

sudo systemctl start postgresql.service

Optionally, you lot can automatically start PostgreSQL on boot past typing:

                  
                                              

sudo systemctl enable postgresql.service

By default, PostgreSQL is configured to apply peer hallmark, which allows users to log in if their operating system user proper name matches a PostgreSQL internal name.

The installation process created an operating organization user called postgres to match the postgres database administrative business relationship. To log into PostgreSQL with the psql customer, use sudo to run the command as the postgres user:

                

When yous are finished, you can leave the psql session by typing:

              

Install using the PostgreSQL project's CentOS and Fedora repositories

If you need a more up-to-date version of PostgreSQL, y'all can use the repositories maintained past the PostgreSQL projection instead of those provided by your Linux distribution.

To configure the PostgreSQL project'due south repository, download and install the repository setup package with in your terminal.

For CentOS execute the following command:

                  
                                              

sudo yum install "https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(. /etc/os-release; echo $VERSION_ID)-x86_64/pgdg-redhat-repo-latest.noarch.rpm"

For Fedora employ this command:

                  
                                              

sudo dnf install "https://download.postgresql.org/pub/repos/yum/reporpms/F-$(. /etc/os-release; echo $VERSION_ID)-x86_64/pgdg-fedora-repo-latest.noarch.rpm"

If you lot are using CentOS 8, you must also disable the organisation'south PostgreSQL module to prevent it from interfering with the repository's PostgreSQL version. To practise then, type:

                  
                                              

sudo yum module disable postgresql

Next, choose the version of PostgreSQL that you wish to target.

For CentOS, check which versions of PostgreSQL are available by typing:

                  
                                              

yum list postgresql*-server

For Fedora utilize the dnf package manager:

                  
                                              

dnf listing postgresql*-server

After deciding which version to utilize, you can install information technology using your package director.

For CentOS use the yum package manager. For example, to install PostgreSQL 12, type:

                  
                                              

sudo yum install postgresql12-server

For Fedora apply the dnf package managing director. For case, to install PostgreSQL 12, blazon:

                  
                                              

sudo dnf install postgresql12-server

Once the PostgreSQL package is installed, initialize the database:

                  
                                              

sudo /usr/pgsql-*/bin/postgresql-*-setup initdb

Find the name of the systemd unit file for your version of PostgreSQL:

                  
                                              

systemctl list-unit-files | grep postgresql

Start up the service using the unit file you lot found. For case, for PostgreSQL 12, it would be:

                  
                                              

sudo systemctl outset postgresql-12.service

Optionally, y'all can also automatically kickoff PostgreSQL on boot with the enable:

                  
                                              

sudo systemctl enable postgresql-12.service

By default, PostgreSQL is configured to employ peer hallmark, which allows users to log in if their operating system user name matches a PostgreSQL internal proper noun.

The installation procedure created an operating system user chosen postgres to match the postgres database administrative account. To log into PostgreSQL with the psql client, employ sudo to run the command equally the postgres user:

                

When y'all are finished, you can leave the psql session by typing:

              

About the Author(south)

Justin Ellingwood

Justin Ellingwood

Justin has been writing about databases, Linux, infrastructure, and developer tools since 2013. He currently lives in Berlin with his wife and two rabbits. He doesn't ordinarily take to write in the tertiary person, which is a relief for all parties involved.

Source: https://www.prisma.io/dataguide/postgresql/setting-up-a-local-postgresql-database

Posted by: bessettemorce1984.blogspot.com

0 Response to "How To Open Postgresql Database In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel