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

Categories: notes, postgresql Tags: ,

end-to-end-encryption-with-openshift-part-1-two-way-ssl

January 25, 2017 Leave a comment

This is the first part of a 2 part article, part 2 (End To End Encryption With OpenShift Part 2: Re-encryption) will be authored by Matyas Danter, Sr Consultant with Red Hat, it will be published soon. This article aims to demonstrate use cases for Openshift routes to achieve end-to-end encryption. This is a desirable and sometimes…

via End To End Encryption With OpenShift Part 1: Two-Way SSL — RHD Blog

Categories: Interesting

Deep Learning enables you to hide screen when your boss is approaching

January 19, 2017 Leave a comment
Categories: Interesting

Cracking 12 character passwords

January 10, 2017 Leave a comment
Categories: Interesting

Top 10 Python libraries of 2016 — thoughts…

December 23, 2016 Leave a comment

Last year, we did a recap with what we thought were the best Python libraries of 2015, which was widely shared within the Python community (see post in r/Python). A year has gone by, and again it is time to give due credit for the awesome work that has been done by the open source […]

via Top 10 Python libraries of 2016 — thoughts…

Categories: Interesting

Clear highlighting on escape in normal mode

December 22, 2016 Leave a comment

Problem:
How to disable highlighted text after doing a search in vim?

Solution:
Added the following to my .vimrc

 " Clear highlighting on escape in normal mode
 nnoremap <esc> :nohlsearch<return><esc>
 nnoremap <esc>^[ <esc>^[

System details:
vagrant box running ubuntu/trusty64

Source:
http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting?rq=1

Categories: vim Tags: ,

Custom Colors

December 21, 2016 Leave a comment

Problem:
I had set up my vim to run flake8 when I save python files. The issue now was that the quickfix window would display the errors in white/white-grey text on a yellow background. That proved to be really hard to read.

white on yellow

Solution:
1. One option was to change my colorscheme to something that would display the text. (Many hours later I still had not found a colorscheme that I liked.)
2. Change the color for just that “aspect”.

So I went with option 2 and changed the color. Which resulted in black on yellow and is now much easier to read.
screen-shot-2016-12-21-at-22-13-58

Steps:
While in vim look at the current colors that are already set. (:highlight or :hi)

:highlight

highlight

The colors I wanted to change were for ‘Search’. So while still in vim

:highlight Search term=reverse ctermbg=11 ctermfg=0  guibg=Yellow

To make this permanent I added the following to .vimrc

highlight clear
highlight Search term=reverse ctermbg=11 ctermfg=0  guibg=Yellow

Source:
http://andrewradev.com/2011/08/06/making-vim-pretty-with-custom-colors/
http://superuser.com/questions/654919/how-to-turn-off-gvim-error-highlighting

Categories: vim Tags: