Skip to content

Instantly share code, notes, and snippets.

View hooopo's full-sized avatar
🍏
I may be slow to respond.

Hooopo hooopo

🍏
I may be slow to respond.
View GitHub Profile
\copy (SELECT row_number() over() AS "序号", n.nspname AS "系统名", c.relname AS "英文表名", d.description AS "字段中文名", a.attname AS "字段英文名", format_type(a.atttypid, a.atttypmod) AS "数据类型", a.attnotnull as "是否为空", coalesce(i.indisprimary, false) AS "是否主键", def.adsrc AS "默认值" FROM pg_attribute a LEFT JOIN pg_class c ON a.attrelid = c.oid LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_description d ON (c.oid = d.objoid AND a.attnum = d.objsubid) LEFT JOIN pg_index i ON (c.oid = i.indrelid AND i.indkey[0] = a.attnum) LEFT JOIN pg_attrdef def ON (a.attrelid = def.adrelid AND a.attnum = def.adnum) WHERE c.relkind in ('r', '') AND pg_catalog.pg_table_is_visible(c.oid) AND n.nspname != 'pg_catalog' AND n.nspname != 'information_schema' AND n.nspname != 'public' AND n.nspname !~ '^pg_toast' AND a.attname NOT IN ('cid', 'xid', 'xmin', 'xmax', 'cmin', 'cmax', 'ctid', 'tableoid') ORDER BY 2,3) to '~/columns.csv' with csv head
\copy (SELECT row_number() over() AS "序号", n.nspname as "系统名", c.relname as "表名",pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "大小",pg_catalog.obj_description(c.oid, 'pg_class') as "中文名",c.reltuples AS "条数" FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1 DESC,2) to '/tmp/tables.csv' WITH CSV HEADER;
https://press.one/p/v?s=d711d89b6ca466486cb55c611b7c4158d2c5b79adb83bf9cec0de77494f89d118ed4676db9b7c49c1b01006f4cb3118389adc2cfdf37cef69b1279830bb7e5d40&h=b52e39bbb8a93da22986862cf28358f6636329c0dbad3ba0e7c22fae5f63985b&a=94a33e5f9859fb073ea35676bae9df7e17602aa9&f=P1&v=2
CREATE DATABASE chronicle ENCODING 'UTF-8' LC_COLLATE = 'C' LC_CTYPE = 'C' TEMPLATE template0;
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
sql = <<~SQL
SELECT n.nspname || '.' || c.relname as "name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
AND pg_catalog.pg_table_is_visible(c.oid)
SQL
@hooopo
hooopo / test.xml
Created October 20, 2018 06:41
Your XPATHr Gist test
Paste your XML code..
@hooopo
hooopo / 0-readme.md
Created October 12, 2018 18:13 — forked from toolmantim/0-readme.md
Using rvm and node on Ubuntu with Buildkite Agent

Firstly, you'll need to install rvm as the buildkite-agent user:

sudo su buildkite-agent
curl -sSL https://get.rvm.io | bash -s stable
source /var/lib/buildkite-agent/.rvm/scripts/rvm
rvm install 2.4.0 && rvm use 2.4.0 && gem install bundler

Secondly, make rvm available to your build commands by adding the following pre-command Buildkite Agent hook:

@hooopo
hooopo / newrelic_instrumenter.rb
Created June 27, 2018 04:33 — forked from nettofarah/newrelic_instrumenter.rb
sample newrelic instrumenter for graphql-ruby
# NewRelic instrumenter for GraphQL-ruby
#
# In your controller:
# ::NewRelic::Agent.add_custom_attributes({
# user_id: @user.try(:id),
# query_string: @query_string,
# query_arguments: @query_variables
# })
#
# @document = self.class.trace_execution_scoped(["GraphQL#parse"]) do
@hooopo
hooopo / Dockerfile
Last active June 21, 2018 03:24 — forked from rtacconi/Dockerfile
Alpine Linux, jemalloc, Ruby 2.4.1 segmentation fault
FROM alpine:3.4
# skip installing gem documentation
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
ENV RUBY_MAJOR 2.5