Skip to content

Instantly share code, notes, and snippets.

View michelp's full-sized avatar

Michel Pelletier michelp

  • Portland, OR
View GitHub Profile
postgres=# \i /tests/single.sql
Going to single user mode
waiting for server to shut down...2019-03-05 07:25:44.650 UTC [108] LOG: received fast shutdown request
.2019-03-05 07:25:44.652 UTC [108] LOG: aborting any active transactions
2019-03-05 07:25:44.653 UTC [116] FATAL: terminating connection due to administrator command
2019-03-05 07:25:44.665 UTC [108] LOG: background worker "logical replication launcher" (PID 115) exited with exit code 1
2019-03-05 07:25:44.665 UTC [110] LOG: shutting down
2019-03-05 07:25:44.693 UTC [108] LOG: database system is shut down
done
server stopped
michel@chrx:~/dev/pggraphblas$ ./test.sh
force rm previous container
Error: No such container: pggraphblas-test-db
building test image
Sending build context to Docker daemon 422.9kB
Step 1/9 : FROM postgres:11
---> f9b577fb1ed6
Step 2/9 : RUN apt-get update && apt-get install -y make cmake git postgresql-server-dev-11 postgresql-11-pgtap postgresql-11-dbgsym curl build-essential m4 sudo gdb
---> Using cache
---> 719990842ff4
psql (11.1 (Debian 11.1-1.pgdg90+1))
Type "help" for help.
postgres=# \i test.sql
CREATE EXTENSION
CREATE EXTENSION
CREATE TABLE
INSERT 0 10
CREATE FUNCTION
select (regexp_matches(substring(query from 41), E'\"([a-z_]*)\"'))[1] as endpoint,
sum(calls) as calls,
sum(total_time) as total_time_ms,
avg(mean_time) as mean_time_ms,
avg(stddev_time) as stddev_time_ms,
sum(shared_blks_hit) as shared_blks_hit,
sum(shared_blks_read) as shared_blks_read,
sum(shared_blks_dirtied) as shared_blks_dirtied
from admin.pg_stat_statements()
where query ilike '%_postgrest_t%'
@michelp
michelp / postgrest-quick.sh
Last active April 13, 2022 21:42
From nothing to REST API with PostgREST
# Minimal example of getting a PostgREST API running from scratch for
# testing purposes. It uses docker to launch a postgres database and
# a postgrest api server.
# This should not be used to deploy a production system but to
# understand how postgrest works. In particular there is no security
# implemented, see the docs for more.
# https://postgrest.org/en/v4.4/
@michelp
michelp / postgrest-quick.sh
Last active May 14, 2018 22:40
From nothing to API server with postgREST
# Minimal example of getting a PostgREST API running from scratch for
# testing purposes. It uses docker to launch a postgres database and
# a postgrest api server.
# This should not be used to deploy a production system but to
# understand how postgrest works. In particular there is no security
# implemented, see the docs for more.
# https://postgrest.org/en/v4.4/
```
create table foo.stuff (
value integer,
date timestamp
)
insert into foo.stuff values (42, '2017-09-10');
insert into foo.stuff values (52, '2017-09-11');
insert into foo.stuff values (62, '2017-09-12');
$ export POSTGRAPHQL_ENV=development
$ export DEBUG=${DEBUG-postgraphql*,-postgraphql:graphql,-postgraphql:postgres:explain}
$ echo $DEBUG
postgraphql*,-postgraphql:graphql,-postgraphql:postgres:explain
$ postgraphql -c postgresql://postgraphql:postgraphql@localhost:5432/postgres --schema ct -n 0.0.0.0 --watch
PostGraphQL server listening on port 5000 🚀
‣ Connected to Postgres instance postgres://localhost:5432/postgres
‣ Introspected Postgres schema(s) ct
postgres=# create table article_bug (id uuid, url text, data jsonb, text_search_vectors tsvector, created timestamp without time zone, dup boolean, simhash varchar, tree_pickle bytea, nltk jsonb);
CREATE TABLE
Time: 12.087 ms
postgres=# select master_create_distributed_table('article_bug', 'id', 'hash');
master_create_distributed_table
---------------------------------
(1 row)
Time: 10.927 ms
postgres=# explain select count(*) from article;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------