

The network port that the PostgreSQL server is running on. The -h option is used to specify the hostname. The network host name or the IP address of the PostgreSQL server. So if your current user is a valid PostgreSQL user on your local database, you can connect by typing: Peer authentication authenticates users automatically if a valid PostgreSQL user exists that matches the user's operating system username. It uses your operating system username as the PostgreSQL username and database name that you are trying to connect to.īy default, modern versions of PostgreSQL are configured for something called peer authentication. Without any arguments, the psql command attempts to connect to a Unix socket file to access a local database. Let's start with connecting to a database from the same computer. remote connection: where the client is connecting to a network-accessible PostgreSQL instance running on a different computer.local connection: a connection where the client and the PostgreSQL instance are located on the same server.For clarity's sake, we'll differentiate between local and remote connections: In the following sections, we'll go over some of the basic connection options. The way that you connect depends on the configuration of the PostgreSQL server and the options available for you to authenticate to an account. In addition, psql is great for interactive exploration or ad-hoc queries while developing the access patterns your programs will use. It is especially useful when implementing your initial settings and getting the basic configuration in place, prior to interacting with the database through application libraries. The psql client, the native command line client for PostgreSQL, can connect to database instances to offer an interactive session or to send commands to the server. If your database client or library requests a connection URI, you may want to look at our guide on understanding PostgreSQL connection URIs instead. Consider reading both guides for a more complete picture of how authentication works in PostgreSQL.
#Postgresql commands how to
In a companion guide, you can find out how to configure PostgreSQL's authentication to meet your project's needs. In this guide, we'll cover how to connect to a PostgreSQL database using the native psql command line client - one of the most common and useful ways of interacting with a database instance. This requires coordination between the database client - the component you use to interact with the database, and the database server - the actual PostgreSQL instance that stores, organizes, and provides access to your data.īecause of this, you need to understand how to connect as a client by providing the required information to authenticate. One of the first things you'll need to think about when working with a PostgreSQL database is how to connect and interact with the database instance.

#Postgresql commands update

Creating and deleting databases and tables with SQLite.An introduction to MySQL column and table constraints.How to create and delete databases and tables in MySQL.

