Skip to content

Instantly share code, notes, and snippets.

View jackie-do's full-sized avatar
🎯
Focusing

Huy Do jackie-do

🎯
Focusing
View GitHub Profile
# initialization file (not found)
@jackie-do
jackie-do / restore_database_in_docker.md
Last active November 14, 2017 11:14
Restore a postgres database in a docker container
  1. Run the database container only. "docker container start [container name]"

  2. Connect pgAdmin to the docker container

  • Check port of the container, for example: "0.0.0.0:5432->5432/tcp"
  • Create a new connection on pgAdmn: "0.0.0.0:5432"
  1. Remove the old database
@jackie-do
jackie-do / set_up_vim.md
Created January 1, 2018 01:02
Set up vim
" display line number
:set number
" size of a hard tabstop
set tabstop=2
" always uses spaces instead of tab characters
set expandtab
" size of an "indent"
set shiftwidth=2
@jackie-do
jackie-do / [postgresql]_set_up_authentications_postgresql_user.md
Last active January 4, 2018 06:50
Set up authentication methods for postgresql users
  1. Go to config directory
 cd /etc/postgresql/<postgresql_version>/main
  1. Open and update file "pg_hba.conf" to dismiss all authentications for "postgres" user (normally line 85)
  • Before updating
 local   all             postgres                                peer
@jackie-do
jackie-do / [postgresql]_set_up_read_only_user.md
Last active January 4, 2018 06:50
Set up a read-only user for Postgresql
  1. Create a linux user and set password
sudo adduser read_access

.. then enter your password for this user

  1. Limit permission for the user (option) .. normally, this user only has root permission on it's directory. (/home/read_access)

  2. Set read-only role for this user to use Postgresql

@jackie-do
jackie-do / [postgresql]_dump_and_restore.md
Last active January 4, 2018 06:51
dump and restore a table
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser -d mydb -t mytable > mydb.dump

=== RESTORE ===

psql -U boxatwork_newqa -d boxatwork_newqa -1 -f ../../../boxie24_production/shared/db_bk/store_blog_categories_april_24.dump

psql -U boxatwork_newqa -d boxatwork_newqa -1 -f store_blog_categories_april_24.dump
@jackie-do
jackie-do / [postgresql]_update_auto_increment_field_manually.md
Last active January 4, 2018 07:12
Update the sequence field (auto increment field) manually
  • Get the max current value of a field (base on current data)
SELECT MAX(<field_name>) FROM <table_name>;

example:

SELECT MAX(id) FROM blogs;
@jackie-do
jackie-do / [linux]_install_redis_on_ubuntu_16.md
Last active January 21, 2018 07:48
Set up redis for Ubuntu 16.04

1) Install Prerequisites

sudo apt-get update
sudo apt-get install build-essential tcl

2) Download, Compile, and Install Redis

  • Since we won't need to keep the source code that we'll compile long term (we can always re-download it), we will build in the /tmp directory. Let's move there and download the latest stable version of Redis.

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA <schema_name> TO <username>;

GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA <schema_name> TO <username>;

@jackie-do
jackie-do / [linux]_create_user_without_home_directory_and_set_up_sftp.md
Last active March 12, 2018 07:58
Create a user without home directory and change it's directory to a new path, configure permission.

sudo adduser --no-create-home <username>

sudo usermod -d /path/to-a-directory <username>