Archive

Archive for the ‘notes’ Category

PostgreSQL – Create users and assign roles

January 25, 2017 Leave a comment

1. Create role.

CREATE ROLE myuser LOGIN PASSWORD 'mypassword';

2. Alter role.

ALTER ROLE myuser CREATEDB CREATEROLE;

3. Create database.

$ createdb mydatabase -U myuser -h 127.0.0.1 -p 5432;

4. Connect as new user.

psql -h 127.0.0.1 -p 5432 -U myuser;

5. Delete role

DROP OWNED BY myuser cascade;
DROP ROLE myuser;
$sudo -u postgres psql postgres
psql (9.4.10)
Type "help" for help.

postgres=# CREATE ROLE myuser LOGIN PASSWORD 'mypassword';
CREATE ROLE
postgres=# \dg
                                List of roles
   Role name    |                   Attributes                   | Member of
----------------+------------------------------------------------+-----------
 myuser         |                                                | {}
 postgres       | Superuser, Create role, Create DB, Replication | {}
 
 vagrant        |                                                | {}

postgres=# ALTER ROLE myuser CREATEDB CREATEROLE;
ALTER ROLE
postgres=# \dg
                                List of roles
   Role name    |                   Attributes                   | Member of
----------------+------------------------------------------------+-----------
 myuser         | Create role, Create DB                         | {}
 postgres       | Superuser, Create role, Create DB, Replication | {}
 
 vagrant        |                                                | {}

postgres=#\q



$ psql -h 127.0.0.1 -p 5432 -U myuser;
Password for user myuser:
psql: FATAL:  database "myuser" does not exist



$ createdb mydatabase -U myuser -h 127.0.0.1 -p 5432; 
Password:



$ psql -h 127.0.0.1 -p 5432 -U myuser -d mydatabase; 
Password for user myuser:
psql (9.4.10)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

mydatabase=> \dt
No relations found.

mydatabase=> \q

Source:
https://www.postgresql.org/docs/current/static/sql-createrole.html
http://grokbase.com/t/postgresql/pgsql-patches/068m331a82/drop-owned-by-doesnt-work

Advertisements
Categories: notes, postgresql Tags: ,

apt-get notes

September 26, 2016 Leave a comment

A nice summary of some apt-get commands.

# Installs the selected package from repositories listed in
# /etc/apt/sources.list
$ apt-get install <package>

# Installs the selected package from repositories listed in
# /etc/apt/sources.list
$ apt-get install <package>

# Removes the selected package from your system
$ apt-get remove <package> 

# Updates the list of packages available on the repositories listed in
# /etc/apt/sources.list
$ apt-get update

# Installs the latest available versions of all your installed software
$ apt-get upgrade

# Installs the latest available software related to your configuration
$ apt-get dist-upgrade 

# Restarts/Starts the configuration script inside the package, 
# which will bring up the menu-based dialogs in the same way as after installation
$ dpkg-reconfigure

# Prints detailed information about the software package
$ apt-cache show <package> 

# Prints information on the installed software package
$ dpkg -l <package>

# Lists all files installed by the software package
$ dpkg -L <package>

# Installs a local (.deb) file to your system
$ dpkg -i <file>

# Prints information about the software package owning <file>
$ dpkg -S <file>

# Searches apt database for packages containing <string> in their 
# name and description
$ apt-cache search <string>

Source:
OpenVPN: Building and Integrating Virtual Private Networks

Categories: bash, debian, notes Tags: ,

Splitting up the settings file

July 5, 2016 Leave a comment

If you use a source control system (CVS, SVN, …), or want to publish your application on the web, it may be a good idea to move sensitive or machine/user specific settings like database passwords and such out of the main settings.py file.

As discussions on the ​django-developers mailing list have shown everybody has different requirements and ideas how to do this. This page is meant to collect some of these ideas for future reference.

One thing to keep in mind is that Django’s config files are pure Python. This gives you the ultimate flexibility to handle configurations the way you think is best. Or to quote Adrian Holovaty:

We don’t need a default solution for this. It’s not within the scope of this project to tell people how they should organize their settings files. Take that opportunity to showcase your individualism.

https://code.djangoproject.com/wiki/SplitSettings

Categories: django, notes