Skip to content

Instantly share code, notes, and snippets.

steve-chavez /
Created September 5, 2022 22:06 — forked from lovubuntu/
History for psql commands

There's no history in the database itself, if you're using psql you can use "\s" to see your command history there.

You can get future queries or other types of operations into the log files by setting log_statement in the postgresql.conf file. What you probably want instead is log_min_duration_statement, which if you set it to 0 will log all queries and their durations in the logs. That can be helpful once your apps goes live, if you set that to a higher value you'll only see the long running queries which can be helpful for optimization (you can run EXPLAIN ANALYZE on the queries you find there to figure out why they're slow).

Another handy thing to know in this area is that if you run psql and tell it "\timing", it will show how long every statement after that takes. So if you have a sql file that loo

steve-chavez / makefile
Created June 22, 2022 17:40 — forked from ArtemGr/makefile
SPI helper for a PostgreSQL CHECK when using one-to-many with a jsonb.
View makefile
all: spi.o makefile
g++ -shared -o spi.o
cp --remove-destination /var/lib/postgresql/
spi.o: makefile
g++ -g -O2 -Wall -std=c++11 -fpic -c -o spi.o -I/usr/include/postgresql -I/usr/include/postgresql/9.4/server
steve-chavez / Arcan.nix
Created April 29, 2021 14:45 — forked from egasimus/Arcan.nix
Building Arcan on NixOS, 2020 version
View Arcan.nix
({ lib, newScope, stdenv, pkgs }: let
# nicer aliases
derive = stdenv.mkDerivation;
concat = builtins.concatStringsSep " ";
# vendored libuvc: don't build, just make sources available
libuvc-src = derive {
name = "libuvc-src";
# using fetchgit instead fetchFromGitHub because
View diff_demo.sql
-- This script was generated by the Schema Diff utility in pgAdmin 4
-- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
-- and may require manual changes to the script to ensure changes are applied in the correct order.
-- Please report an issue for any failure with the reproduction steps.
-- Cast: money -> bigint
View schema_diff_output.json
"success": 1,
"errormsg": "",
"info": "",
"result": null,
"data": [
"id": 326,
"type": "cast",
"label": "Casts",
steve-chavez / Dockerfile
Last active September 27, 2022 17:29
Metarest: create database objects from Supabase client libs
View Dockerfile
FROM postgres
RUN metaDependencies="git \
ca-certificates \
build-essential" \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${metaDependencies} \
&& apt-get install -y build-essential \
&& apt-get install make \
&& cd /tmp \
steve-chavez / map.sql
Last active January 31, 2022 02:25
Create a OSM map from a pg function with PostgREST
View map.sql
-- From
-- +
-- +
CREATE TABLE coffee_shops
id serial NOT NULL,
name character varying(50),
address character varying(50),
city character varying(50),
state character varying(50),
View deploy.nix
# From:
region = "us-east-2";
accessKeyId = "dev";
in {
network.description = "";
resources = {
ec2KeyPairs.xyzKeyPair = { inherit region accessKeyId; };
elasticIPs.xyzIP = { inherit region accessKeyId; };
steve-chavez /
Created April 25, 2020 23:07 — forked from denji/
NGINX tuning for best performance

Moved to git repository:

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

steve-chavez / foundation.nix
Created January 13, 2020 17:48 — forked from monacoremo/foundation.nix
(Ab-)using Nix for full stack development environments
View foundation.nix
pkgs =
pinnedPkgs =
builtins.fetchGit {
name = "nixos-unstable-2019-12-05";
url =;
rev = "cc6cf0a96a627e678ffc996a8f9d1416200d6c81";