Skip to content
Archive of posts filed under the Postgres category.

One More Graph, SQL to R

import psycopg2 conn = psycopg2.connect( “dbname=example_db” ) curs = conn.cursor() tSQL = ”’ select emp_gden_min, res_units_gden_min, emp_gden_max, res_units_gden_max from p_translation_table; ”’ curs.execute( tSQL ) resT = curs.fetchall() from rpy2.robjects.packages import importr grdevices = importr( ‘grDevices’ ) grdevices.pdf(file=’/home/shared/aab.pdf’) r_plot_str = ”’ plot(c(0,1000),c(0,2000),type=”n”,log=”xy”,xlim=c(0.1,1000),ylim=c(0.1,2000), xlab=”employment”, ylab=”residence”) ”’ rpy2.robjects.r( r_plot_str ) tC = 0 for n in resT:   tStr2 […]

Killing a Pg Query on Linux

kill => linux utility to send a signal to a process pid => a process ID Using the linux kill utility, a user with sufficient privileges could terminate a running Postgres query specified by process ID (pid). This is a bad idea though, because it will cause PostgreSQL to panic. It is useful to know […]

Pg Jobs Active

I keep this one line as .sql in my home directory of all the work machines: ## PG10 Syntax SELECT datname,usename,pid,client_addr,wait_event,query_start,query FROM pg_stat_activity ; checking what is going on is easy psql -f short_queries_list.sql per the manual http://www.postgresql.org/docs/current/static/monitoring-stats.html

Extract and Sum Classified Areas by Grid Cell

Given a set of classified polygons, in this example classified into three categories by name, apply a reference grid, and sum the areas for each classification into float fields in a destination table. This code contains test harness pieces in it also, so that a smaller example can be executed and verified, before applying the […]

Super Double-Box Search-Off

“A quick estimate of performance of PostGIS 2 with geometry bounding boxes as doubles vs as floats” All tests performed on Linux 2.6.38 x86_64 PostgreSQL 9.0.5 shared_buffers = 2400MB temp_buffers = 64MB work_mem = 512MB maintenance_work_mem = 200MB The Test – TIGER 2010 California TIGER provides many possibilities for tests.. The one I chose here […]