Tuesday, March 27, 2018

Install pgadmin4 on Ubuntu

apt-get install virtualenv python-pip libpq-dev python-dev

wget whl file

mkdir pgadmin4

cd pgadmin4

virtualenv .

source bin/activate

pip install whlfile

echo "SERVER_MODE = False" >> lib/python2.7/site-packages/pgadmin4/config_local.py

sudo -s

mkdir /var/lib/pgadmin

mkdir /var/log/pgadmin

chmod gbsofts:gbsofts /var/lib/pgadmin

chmod gbsofts:gbsofts /var/log/pgadmin

exit


Create desktop icon
nano pgadmin4.desktop
#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=gnome-panel-launcher
Name[en_US]=PgAdmin4
Exec=bash /home/gbsofts/pgadmin4/pgadmin4.sh
Name=PgAdmin4
Icon=/home/gbsofts/pgadmin4/logo-128.png

chmod 755 pgadmin4.desktop

Create script
nano pgadmin4.sh
cd $HOME/pgadmin4
source bin/activate
python ./lib/python2.7/site-packages/pgadmin4/pgAdmin4.py  &
sleep 5; chromium-browser --app=http://localhost:5050

Monday, February 12, 2018

Enable socket admin Haproxy

The stats socket is not enabled by default. In order to enable it, it is
necessary to add one line in the global section of the haproxy configuration.
A second line is recommended to set a larger timeout, always appreciated when
issuing commands by hand :

    global
        stats socket /var/run/haproxy.sock mode 600 level admin
        stats timeout 2m

It is also possible to add multiple instances of the stats socket by repeating
the line, and make them listen to a TCP port instead of a UNIX socket. This is
never done by default because this is dangerous, but can be handy in some
situations :

    global
        stats socket /var/run/haproxy.sock mode 600 level admin
        stats socket ipv4@192.168.0.1:9999 level admin
        stats timeout 2m

Saturday, October 21, 2017

Free SSL Certificate with Let's Encrypt


1. Install git
apt-get install git

2. Create Let's Encrypt source directory
mkdir /opt/letsencrypt

3. Clone source of Let's Encrypt
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt

4. Stop web server (apache, tomcat, nginx...) because they can cause of port 443 error

5. Create certificate for specified domain
cd /opt/letsencrypt 
./letsencrypt-auto certonly --standalone -d example.com -d www.example.com

6. All certificates have created in /etc/letsencrypt/live

7. Config fullchain.pem for certificate file, privkey.pem for key file

For HaProxy, create .pem file
cat fullchain.pem privkey.pem > secure.pem

By default, Let's Encrypt issue certificate valid for 90 days, so we need config automatically renew it

1. create auto_renew_cert.sh file as below:
cd /opt/letsencrypt
git pull
service nginx stop
./letsencrypt-auto certonly --quiet --standalone --renew-by-default -d example.com
service nginx start


2.  execute it in crontab monthly
echo '@monthly root sh /root/auto_renew_cert.sh >> /var/log/letsencrypt/letsencrypt-auto-update.log' | sudo tee --append /etc/crontab





Saturday, June 24, 2017

Portable Postgres

Postgres full extension 9.6.3 on Debian 8 64bit 
https://drive.google.com/open?id=0B30EeVPAcvhvWHpMNDZmbFdNYVk

Friday, March 17, 2017

Install Redmine

gem install passenger --no-ri --no-rdoc
passenger-install-nginx-module

http://coderazzi.net/linux/debian/redmine.htm

Thursday, February 9, 2017

Function slower than query direct Postgres

For queries on tables with even data distribution, this will generally be no problem and PL/pgSQL functions will perform somewhat faster than raw SQL queries or SQL functions. But if your query can use certain indexes depending on the actual values in the WHERE clause or, more generally, chose a better query plan for the particular values, you may end up with a sub-optimal query plan.
(source: http://stackoverflow.com/questions/9305133/why-does-postgresql-treat-my-query-differently-in-a-function)

RETURN QUERY : cache plan
RETURN QUERY EXECUTE: replan for each call

RETURN QUERY EXECUTE $$
//query body
$$ USING param1, param2

Saturday, February 4, 2017