Everything you’ve ever wanted is on the other side of fear.
George Addair
Author: abhijit
error – sudo without being in the sudo group?

This was quite a head-scratcher. I wanted to remove a user sammy
from the sudo
group and did that by running this as root
root> deluser sammy sudo
However, when I logged in as sammy
I was still able to run –
sammy> sudo su
Checking which groups the user belonged to was of no help either.
sammy> groups sammyContinue reading
When in doubt, choose the adventure.
Friedrich Nietzche
Postgres pg_dump without password

I have to do a dump of a Postgres database on a regular basis.
So pg_dump
is the obvious choice to do this as is cron
to do this periodically.
But the main problem with this is – pg_dump
expects a password to be entered at the prompt. There’s no way to pass the password in the prompt to be able to do this.
Stackoverflow to the rescue.
What is required is a .pgpass
file in the home
directory.
‘asdf’ not finding program

I discovered asdf quite late! I was relying on a bunch of different programs to manage Ruby (rvm), Node (nvm).
asdf was an amazing headache saver. It already has core plugins for Elixir, Erlang, Node and Ruby. Plus, it has community plugins for what seems like practically anything under the sun.
I had installed asdf on a new system. And as usual, there were some crons to run on it. I kept getting a /bin/bash/ruby not found
error.
After some time I realized I had faced this problem before as well!
Continue readingConnect to server running on host from inside a Docker container

After installing the CloudBeaver as a Docker instance, I was trying to connect to the Postgres instance which I was running on my local machine.
In the HOST field, I tried with localhost
which obviously wouldn’t work since that refers to the VM itself.
After some searching I found that to connect to the host, I need to set the connection as
host.docker.internal
Ruby Sequel migration – increment column in a group

The requirement was to add a column called position
to the order_details
table.
The order_details
table is actually a table with a foreign key of order_id
. The requirement is to increment the position starting from 1
in the position
column grouped on order_id
.
So, before the migration if the records are –
id order_id 1 1 2 1 3 1 4 2 5 2 6 2
After the migration, the records should be –
id order_id position 1 1 1 2 1 2 3 1 3 4 2 1 5 2 2 6 2 3
There are two solutions possible. One using window functions
and one without.
How to generate SSH Keys and avoid “Invalid privatekey” error

I’ve long been a user of DBeaver which works so well across different OSes, so recently I wanted to set up the cloud version called cloudbeaver.
In the course of doing that, I had to generate SSH keys to be able to access remote databases via SSH.
Generate an SSH keypair
The standard way of generating SSH keys is to run this command.
> ssh-keygen -t rsa
This by default creates id_rsa
and id_rsa.pub
under <home directory>/.ssh
folder (both in Windows and Linux)
increase Postgres statement_timeout

Sometimes it is required to increase the statement_timeout
for Postgres.
The correct way to do this would be to create a .psqlrc
in the home directory and add the setting inside there.
$> cat .psqrc set statement_timeout to 10000;
This is given in milliseconds so the above is for 10 seconds.
This can be verified from within psql
command
psql> show statement_timeout; statement_timeout ------------------- 10s (1 row)
Reference: https://stackoverflow.com/a/24093305/33581
PM2 logrotate

One of the things I forgot when I wrote the PM2 post is that PM2 creates logs. And these logs get very big, very fast!!
The pm2-logrotate takes care of this.
To install pm2-logrotate
$> pm2 install pm2-logrotate
The defaults work perfectly fine. It will retain logs for 30 days and rotate the log every day, each with a max-size of 10 MB.
To change any of these settings –
$> pm2 set pm2-logrotate:max_size 1K (1KB) $> pm2 set pm2-logrotate:compress true (compress logs when rotated) $> pm2 set pm2-logrotate:rotateInterval '*/1 * * * *' (force rotate every minute)