Home / ساخت حساب کاربری برای دیتابیس postgres

ساخت حساب کاربری برای دیتابیس postgres


sudo su - postgres
psql
create USER databaseuser with password 'yourpassword';
CREATE DATABASE myproject;
We are setting the default encoding to UTF-8, which Django expects. We are also setting the default transaction isolation scheme to "read committed", which blocks reads from uncommitted transactions. Lastly, we are setting the timezone. By default, our Django projects will be set to use UTC:

ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';
Now, all we need to do is give our database user access rights to the database we created:

GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
Exit the SQL prompt to get back to the postgres user's shell session:

\q
Exit out of the postgres user's shell session to get back to your regular user's shell session:

exit


django settings
pip install django psycopg2


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'myproject',
        'USER': 'myprojectuser',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '',
    }
}



how to connect to database from shell


psql --username=username --password -d dbname -h 127.0.0.1

on getting password error
nano /var/lib/pgsql/data/pg_hba.conf
on local server only
change this to line:

host all all ::1/128 ident
host    all             all             ::1/128                 ident

to:
host    all             all             ::1/128                 trust
host    all             all             ::1/128                 trust





     RSS of this page