Psql -d test -f test_backup.sql Comments and ConclusionĪt this point, you learn to set up PostgreSQL 15 on Debian 11. You can also restore a single database using psql command.įor example, to restore a single database named test from a backup file named test_backup.sql, run the following command: su - postgres You can back up and restore a single database using the pg_dump utility.įor example, to back up a single database named test and generate a backup file named test_backup.sql, run the following command: su - postgres To exit from the shell, run the following command: exit 4. You should see all tables in the following output: List of relations To list all tables, run the following command: \dt To create a table (e.g accounts), run the following command: CREATE TABLE accounts ( To switch the database to test, run the following command: \c test You should see all databases in the following output: To list all databases, run the following command: \l To create a database named test, run the following command: CREATE DATABASE test To set the Postgres pasword, run the following command: ALTER USER postgres PASSWORD 'password' Once you have accessed the command shell of Postgres, you can now use SQL queries to perform several database-related operations. In your output you will see: Output psql (15.0 (Debian 15.0-1.pgdg110+1)) Now you can access your PostgreSQL shell with the following command: $ psql To do this run the following command: # su postgres To access your PostgreSQL server, you must log in as a Postgres user. You will get the version in the following output: version You can also check the version using the following command: # sudo -u postgres psql -c "SELECT version() " You can check it with the following command: # ss -antpl | grep 5432 Main PID: 7543 (code=exited, status=0/SUCCESS)īy default, PostgreSQL listens on port 5432. Loaded: loaded (/lib/systemd/system/rvice enabled vendor preset: enabled) Verify that is active and running on your server: # systemctl status postgresql Output Now you can run the following command to install the latest version of the PostgreSQL server: # apt-get install postgresql-15 -yĪfter the successful installation, start the PostgreSQL service and enable it to start after the system reboot: # systemctl start postgresql Update your local package index with the following command: # apt -y update Now import the repository signing key by using the following command: # wget -quiet -O - | sudo apt-key add. To get the latest packages of PostgreSQL, you must add the official repo of PostgreSQL.įirst, install all required dependencies by running the following command: # apt-get install wget sudo curl gnupg2 -yĪfter installing all the dependencies, create the file repository configuration with the following command: # sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt//pgdg.list' PostgreSQL is available in the default Debian repositories but the available versions are not up to date. Install PostgreSQL 15 using the official repository Update your Debian 11 operating system to make sure all existing packages are up to date: # apt update & sudo apt upgrade -y 2. In this guide we are going to install PostgreSQL 15 in Debian 11. It is one of the leading database servers used for production servers. DevOps use it as an alternative to MariaDB. The EOT character can be sent by typing Ctrl+D.PostgreSQL also known as Postgres, is a free and open source object-relational database system that runs on Client-Server architecture. In the case of psql, this will cause the program to exit. The EOT character signals the end of a file to a program that is waiting for input. You can also quit psql using the End-of-Transmission (EOT) character. Exiting psql Using an End-of-Transmission Character ![]() For more information about this and other meta-commands use the meta-command \?. The most common way to exit psql is using a meta-command. ![]() They are denoted by a backslash and then followed by the command and its arguments. Psql has a concept of meta-commands which are commands that are evaluated by psql before ever sending anything to the database server. ![]() Is it quit? quit()? exit? Ctrl+C? I give up! In this tutorial, we’ll go over the exact commands you can use to quit psql. Command line utilities often use different conventions for exiting and it can be difficult to remember the exact command for the utility you’re using.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |