Skip to content

Instantly share code, notes, and snippets.

@manics
Last active September 22, 2023 23:19
Show Gist options
  • Save manics/e1392b4368cff1b92c362f121215ce84 to your computer and use it in GitHub Desktop.
Save manics/e1392b4368cff1b92c362f121215ce84 to your computer and use it in GitHub Desktop.
Example mybinder postgresql server

mybinder/repo2docker PostgreSQL server

Binder

Example mybinder repo with a built-in PostgreSQL server.

name: root
channels:
- defaults
dependencies:
- postgresql
- psycopg2
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Connect using default socket, list databases"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('postgres',), ('template1',), ('template0',)]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import psycopg2\n",
"\n",
"conn = psycopg2.connect(\"dbname='postgres'\")\n",
"cur = conn.cursor()\n",
"cur.execute(\"SELECT datname from pg_database\")\n",
"\n",
"cur.fetchall()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
#!/bin/bash
set -eux
PGDATA=${PGDATA:-/home/jovyan/srv/pgsql}
if [ ! -d "$PGDATA" ]; then
initdb -D "$PGDATA" --auth-host=md5 --encoding=UTF8
fi
#!/bin/bash
set -eux
PGDATA=${PGDATA:-/home/jovyan/srv/pgsql}
pg_ctl -D "$PGDATA" -l "$PGDATA/pg.log" start
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment