Skip to content

Instantly share code, notes, and snippets.

@matteof
matteof / postgres_queries_and_commands.sql
Last active February 24, 2025 20:36 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
CREATE TABLE IF NOT EXISTS mytable
(
pk_id serial PRIMARY KEY,
geom geometry(Polygon,3857),
geohash text
);
CREATE INDEX IF NOT EXISTS mytable_geohash_idx
ON mytable ( ST_GeoHash(ST_Transform(geom,4326), 3 ) ); -- 3
@matteof
matteof / ubuntu20_install_postgreql14.sh
Last active February 17, 2022 07:48
Install postgresql-14 on ubuntu-20.4 and move data-directory
#tested on ubuntu 20.04.3
sudo apt list --upgradable
#create sudoer
sudo adduser devel
sudo usermod -aG sudo devel
sudo apt install vim
sudo apt install python3.9
#add new postgres in APT from https://www.postgresql.org/download/linux/ubuntu/
@matteof
matteof / trac2down.py
Created October 26, 2015 15:28 — forked from sgk/trac2down.py
Trac Wiki to Markdown converter
#!/usr/bin/python
# vim:set fileencoding=utf-8 sw=2 ai:
import sqlite3
import datetime
import re
SQL = '''
select
name, version, time, author, text
@matteof
matteof / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console