Skip to content

Instantly share code, notes, and snippets.

@tanzim
tanzim / postgres_readonly_user.sql
Last active July 20, 2016 10:21
Create a readonly PostgresSQL database user. Tested on 9.5
-- create a user first. For users and roles see
-- https://www.postgresql.org/docs/9.5/static/sql-createrole.html
CREATE USER readonly_user WITH ENCRYPTED PASSWORD 'shhsecret' NOSUPERUSER NOCREATEDB NOCREATEROLE;
-- then grant the user permission to connect to the database (in this case, db)
GRANT CONNECT ON DATABASE db TO readonly_user;
-- finally, grant permission to the user to select (read) tables in the target schema (in this case public)
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_user;
-- turns out that, granting permission to all tables isn't enough, we need grant on sequences too.
-- From https://www.postgresql.org/docs/9.5/static/sql-grant.html:
@tanzim
tanzim / connection.js
Created July 4, 2016 18:42
Streaming data from MongoDB
'use strict';
const mongodb = require('mongodb');
// MongoDB connection defaults
const OPTION_AUTO_RECONNECT = true;
const OPTION_SOCKET_OPTIONS = {
keepAlive: 1,
connectTimeoutMS: 30000
};