UPDATE 05/23/2021
As appears author@YandexZen gave the name of database to table inside it "students". I just couldn't expect such kind of database design, which breaks pretty much common approach - never give the table in database the name exactly matching database name.
END UPDATE
Original post Библиотека PyQT5. Работа с базой данных PostgreSql (библиотека psycopg2)
Fixes have been done to mentioned above post @Yandex Zen
Critical errors have been colored blue. Code Fix in Python :-
def con(self):
self.conn = psycopg2.connect(user = "postgres",
password = "*******",
host = "127.0.0.1",
port = "5432",
database = "db1")
Following setup is completely skipped in original post what obviously demonstrates, that posted code has never been running on real box.
*************************************************
Database Setup PostgreSQL 13.2 on Server Fedora 34
*************************************************
$ sudo dnf module -y install postgresql:13/server
$ sudo postgresql-setup --initdb
$ sudo dnf install python-psycopg2
$ sudo vi /var/lib/pgsql/data/pg_hba.conf
Replacement in field auth-method
"ident" by "md5"
$ sudo systemctl restart postgresql.service
$ sudo -u postgres psql
[sudo] password for boris:
psql (13.2)
Type "help" for help.
postgres=# create database db1 encoding 'UTF8';
CREATE DATABASE
postgres=# grant all privileges on database db1 to postgres;
GRANT
postgres=# SELECT datname FROM pg_database;
datname
-----------
postgres
template1
template0
db1
(4 rows)
postgres=# \c db1
db1=# create table students ( id SERIAL PRIMARY KEY, name VARCHAR,ocenka INT);
postgres=# alter user postgres with encrypted password '*******';
[boris@fedora33server ~]$ hostnamectl
Static hostname: fedora33server.localdomain
Icon name: computer-desktop
Chassis: desktop
Machine ID: fec5966968d24022ad7f9f058b866d8a
Boot ID: 380bfb1a5feb4930b00c63dbb4b96891
Operating System: Fedora 34 (Server Edition)
CPE OS Name: cpe:/o:fedoraproject:fedora:34
Kernel: Linux 5.12.5-300.fc34.x86_64
Architecture: x86-64
Hardware Vendor: ASUS
Hardware Model: All Series
[boris@fedora33server ~]$ sudo systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: d>
Active: active (running) since Sat 2021-05-22 18:41:52 MSK; 1h 37min ago
Process: 9560 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exite>
Main PID: 9562 (postmaster)
Tasks: 8 (limit: 38409)
Memory: 29.8M
CPU: 1.207s
CGroup: /system.slice/postgresql.service
├─9562 /usr/bin/postmaster -D /var/lib/pgsql/data
├─9563 postgres: logger
├─9565 postgres: checkpointer
├─9566 postgres: background writer
├─9567 postgres: walwriter
├─9568 postgres: autovacuum launcher
├─9569 postgres: stats collector
└─9570 postgres: logical replication launcher
May 22 18:41:52 fedora33server.localdomain systemd[1]: Starting PostgreSQL database server>
May 22 18:41:52 fedora33server.localdomain postmaster[9562]: 2021-05-22 18:41:52.852 MSK [>
May 22 18:41:52 fedora33server.localdomain postmaster[9562]: 2021-05-22 18:41:52.852 MSK [>
May 22 18:41:52 fedora33server.localdomain systemd[1]: Started PostgreSQL database server.
lines 1-22/22 (END)
REFERENCES
https://server-gu.ru/add-user-postgres/
https://computingforgeeks.com/install-postgresql-13-on-fedora/