SELECT l.what, l.nr AS "bytes/ct"
, CASE WHEN is_size THEN pg_size_pretty(nr) END AS bytes_pretty
, CASE WHEN is_size THEN nr / x.ct END AS bytes_per_row
FROM (
SELECT min(tableoid) AS tbl -- same as 'public.tbl'::regclass::oid
, count(*) AS ct
, sum(length(t::text)) AS txt_len -- length in characters
FROM radius_db.radacct t -- provide table name *once*
) x
, LATERAL (
VALUES
(true , 'core_relation_size' , pg_relation_size(tbl))
, (true , 'visibility_map' , pg_relation_size(tbl, 'vm'))
, (true , 'free_space_map' , pg_relation_size(tbl, 'fsm'))
, (true , 'table_size_incl_toast' , pg_table_size(tbl))
, (true , 'indexes_size' , pg_indexes_size(tbl))
, (true , 'total_size_incl_toast_and_indexes', pg_total_relation_size(tbl))
, (true , 'live_rows_in_text_representation' , txt_len)
, (false, '------------------------------' , NULL)
, (false, 'row_count' , ct)
, (false, 'live_tuples' , pg_stat_get_live_tuples(tbl))
, (false, 'dead_tuples' , pg_stat_get_dead_tuples(tbl))
) l(is_size, what, nr);
Friday, January 27, 2017
PostgreSQL: size of a row
Source: Measure the size of a PostgreSQL table row
Labels:
postgresql
Thursday, January 19, 2017
mod_perl: how to use environment variable
In httpd.conf:
PerlSetEnv PG_FLG 1In mod_perl code:
sub is_pure_pg {
return exists $ENV{PG_FLG};
}
Friday, January 13, 2017
PostgreSQL: rotate pgbouncer logs
Simplest method: switch to syslog
vi /etc/pgbouncer/pgbouncer.ini
; logfile = /var/log/pgbouncer.log syslog = 1
psql -p6432 -Upostgres -d pgbouncer -c reload
Labels:
postgresql
Wednesday, January 11, 2017
PostgreSQL: split record returned by function into columns
Source: PostgreSQL function or stored procedure that outputs multiple columns?
SELECT a, (func(a)).* FROM table1;
Labels:
postgresql
Tuesday, December 27, 2016
MacOS 10.12: auto mount network drive
Since 10.12, auto-mounting a network drive via Login Items asks to confirm the login and password each time we log in. Very unpleasant.
To get rid of that behavior:
[EDIT] The login / password dialog showing up whenever we log in has been fixed in 10.12.2 at last.
To get rid of that behavior:
- Remove the network drive from the Login Items
- Drag and drop the network drive to the dock
[EDIT] The login / password dialog showing up whenever we log in has been fixed in 10.12.2 at last.
MacOS 10.12: screensaver stuck at: Loading photos
rm ~/Library/Preferences/com.apple.screensaver.plist
Thursday, December 15, 2016
Wednesday, November 30, 2016
Thursday, November 24, 2016
Tuesday, November 15, 2016
Monday, November 7, 2016
PostgreSQL: remove all Bucardo triggers from a schema
do
$$
declare
_row record;
_query text;
begin
for _row in SELECT tgname, tgrelid::regclass as table_name FROM pg_trigger where tgname ~ 'bucardo' and tgrelid::regclass::text ~ 'shared_db' loop
_query := format('drop trigger %s on %s', _row.tgname, _row.table_name);
raise notice '%', _query;
execute _query;
end loop;
end
$$;
Labels:
postgresql
Sunday, November 6, 2016
Google Drive web hosting is shutting down
An alternative is to use Google Firebase.
Create new project on Firebase console : Select Storage : Import your files : Edit your template in Blogger : Copy the Firebase URL of the file you want to use in Blogger : Replace your Google Drive URL : Save your template and you will get an error about token : To workaround the token issue, go to the Google URL shortener, and paste the Firebase URL : Copy the short URL : Replace the Firebase URL with the shortened one in Blogger : [2021-09-05 Edit]
syntaxhighlighter has stopped working for some time now. The Web Dev Tools console in FF shows the following error:
So, it seems as if something changed either in the Google shortener behavior, or maybe in FF itself.
Let's try to re-use the original URLs instead of the shortened ones. As the Blogspot UI changed, you now need to go to "Themes", and click the "Customize" button. Then select the "Edit HTML" menu item. But using, e.g. "https://firebasestorage.googleapis.com/v0/b/syntaxhighlighter-2b128.appspot.com/o/scripts%2FshBrushPhp.js?alt=media&token=1533c104-e33b-43fa-b299-c2dd8c8f81ab" instead of "https://goo.gl/kQztrh" brings back the old error: which is actually caused by the use of "&token=" instead of "&token=".
Once all the URLs have been substituted and the "&token=" occurences replaced, we're back in tracks :)
Create new project on Firebase console : Select Storage : Import your files : Edit your template in Blogger : Copy the Firebase URL of the file you want to use in Blogger : Replace your Google Drive URL : Save your template and you will get an error about token : To workaround the token issue, go to the Google URL shortener, and paste the Firebase URL : Copy the short URL : Replace the Firebase URL with the shortened one in Blogger : [2021-09-05 Edit]
syntaxhighlighter has stopped working for some time now. The Web Dev Tools console in FF shows the following error:
The resource from “https://goo.gl/kQztrh” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
So, it seems as if something changed either in the Google shortener behavior, or maybe in FF itself.
Let's try to re-use the original URLs instead of the shortened ones. As the Blogspot UI changed, you now need to go to "Themes", and click the "Customize" button. Then select the "Edit HTML" menu item. But using, e.g. "https://firebasestorage.googleapis.com/v0/b/syntaxhighlighter-2b128.appspot.com/o/scripts%2FshBrushPhp.js?alt=media&token=1533c104-e33b-43fa-b299-c2dd8c8f81ab" instead of "https://goo.gl/kQztrh" brings back the old error: which is actually caused by the use of "&token=" instead of "&token=".
Once all the URLs have been substituted and the "&token=" occurences replaced, we're back in tracks :)
Thursday, November 3, 2016
PostgreSQL: Find a table columns type
From http://dba.stackexchange.com/questions/75015/query-to-return-output-column-names-and-data-types-of-a-query-table-or-view:
SELECT attname, format_type(atttypid, atttypmod) AS type
FROM pg_attribute
WHERE attrelid = 'foo'::regclass
AND attnum > 0
AND NOT attisdropped
ORDER BY attnum;
Labels:
postgresql
Sunday, October 2, 2016
OSX: Installing Sierra over El Capitan
Information found here:
- Direct Update to macOS Sierra using Clover
- NVIDIA GeForce GTX 260 + Sierra
- Sierra Desktop/Realtek AppleHDA Audio
Install Sierra:
- Update Clover from Clover Configurator, then reboot
- Mount EFI partition like in OSX: use Clover Configurator
- Copy kext to inject from 10.11
cp -R /Volumes/EFI/EFI/CLOVER/kexts/10.11/* /Volumes/EFI/EFI/CLOVER/kexts/Other- Copy NVDAStartup.kext from El Capitan, to avoid a kernel panic on Sierra install
cp -R /Volumes/osx/System/Library/Extensions/NVDAStartup.kext /Volumes/EFI/EFI/CLOVER/kexts/Other- Download Sierra from Mac App Store
- Reboot and choose Boot macOS Install option. Before running the install, press spacebar and tick Without cache + Inject kexts. This will install and start Sierra.
- When Sierra up, re-mount EFI partition
- Remove Sierra NVDAStartup.kext
rm -R /Volumes/osx/System/Library/Extensions/NVDAStartup.kext- Copy NVDAStartup.kext from EFI partition to Desktop
- Install NVDAStartup.kext with KextBeast
- Reboot
Then install audio drivers:
- Re-mount EFI partition
- Run audio_cloverALC command to install Toleda AppleHDA
- Reboot, et voila
Thursday, July 28, 2016
Emacs: disable auto-indent of new lines
This is a new feature from Emacs 24.4.
To revert to the old behavior, you need to disable electric-indent-mode.
To revert to the old behavior, you need to disable electric-indent-mode.
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))See http://emacs.stackexchange.com/questions/5939/how-to-disable-auto-indentation-of-new-lines
Monday, July 11, 2016
CentOS 6 / wkhtmltopdf: extra spaces added in strings when generating PDF from HTML
The tip on this page solved it for me:
sudo wget http://pastebin.com/raw.php?i=AmfYN3er -O /etc/fonts/conf.d/10-wkhtmltopdf.conf
Labels:
centos,
wkhtmltopdf
Wednesday, June 1, 2016
grep extract
Suppose you want 150 lines after the line containing "2016-05-31 11:06:39.265" from file postgresql-31.csv:
grep -A150 '2016-05-31 11:06:39.265' postgresql-31.csv > /tmp/postgresql-31.csv.extract
Subscribe to:
Posts (Atom)














