command: atul@atul-Lenovo-G570:~$ sudo apt install postgresql-<version>
atul@atul-Lenovo-G570:~$ sudo apt install postgresql-17
atul@atul-Lenovo-G570:~$ sudo -u postgres psql
ALTER USER postgres PASSWORD '1****1';
/etc/postgresql/<version>/main/pg_hba.conf
fileatul@atul-Lenovo-G570:~$ sudo gedit /etc/postgresql/17/main/pg_hba.conf
local all postgres peer
. Replace peer with md5 or scram-sha-256, like this local all postgres md5
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
sudo systemctl restart postgresql
postgresql-client
Backup
and Restore
atul@atul-Lenovo-G570:~$ sudo apt install postgresql-client
pg_restore
atul@atul-Lenovo-G570:~$ pg_restore --version
pg_dump
atul@atul-Lenovo-G570:~$ pg_dump --version
pgadmin4.db
atul@atul-Lenovo-G570:~$ sudo rm /var/lib/pgadmin/pgadmin4.db
atul@atul-Lenovo-G570:~$ sudo /usr/pgadmin4/bin/setup-web.sh
http://localhost/pgadmin4
use the pg_dump command
command: $ pg_dump -h [hostname/endpoint] -p [port] -U [username] --column-inserts [database_name] > /path/dir/filename.sql
atul@atul-Lenovo-G570:~$ pg_dump -h localhost -p 5432 -U postgres --column-inserts fprofile_db > mydb/mydatasql.sql
atul@atul-Lenovo-G570:~$ pg_dump -h localhost -p 5432 -U postgres --data-only --column-inserts fprofile_db > mydb/mydatasql1.sql
atul@atul-Lenovo-G570:~$ pg_dump -h localhost -p 5432 -U postgres --table users --column-inserts fprofile_db > mydb/user.sql
atul@atul-Lenovo-G570:~$ pg_dump -h localhost -p 5432 -U postgres --table users --data-only --column-inserts fprofile_db > mydb/users1.sql
command: $ psql -h [hostname/endpoint] -p [port] -U [username] [databasename] -f /path/dir/filename.sql
atul@atul-Lenovo-G570:~$ psql -h localhost -p 5432 -U postgres fprofile_test1 -f mydb/mydatasql.sql
reference: https://neon.tech/postgresql/postgresql-administration/postgresql-schema
Reference: https://www.pgadmin.org/docs/pgadmin4/8.13/backup_dialog.html
/home/atul/mydb/mydb.sql
ERROR: Key (id)=(1) already exists.duplicate key value violates unique constraint "test_pkey"
test_id_seq
TRUNCATE TABLE table_name RESTART IDENTITY;
atul@atul-Lenovo-G570:~$ sudo systemctl status postgresql
atul@atul-Lenovo-G570:~$ sudo systemctl stop postgresql
atul@atul-Lenovo-G570:~$ sudo systemctl disable postgresql
atul@atul-Lenovo-G570:~$ sudo apt remove --purge pgadmin4
atul@atul-Lenovo-G570:~$ sudo apt autoremove
atul@atul-Lenovo-G570:~$ systemctl status postgresql
atul@atul-Lenovo-G570:~$ sudo systemctl enable postgresql
atul@atul-Lenovo-G570:~$ sudo systemctl start postgresql
atul@atul-Lenovo-G570:~$ psql -U postgres
postgres=# \l
\c <database name>
postgres=# \c softbookdb
softbookdb=# \dt
\dt public.*
softbookdb=# \dt public.*
\d <table name>
softbookdb=# \d emp_m
\d+ emp_m
and press q
from keyboard to exit
softbookdb=# \d+ emp_m
softbookdb=# \q
Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.
Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.
comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.
comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.
copyright © 2023