Challenge: can you implement your own small database engine ?

A Simple and Efficient Implementation for Small Databases by Andrew D. Birreil Michael B. Jones Edward P. Wobber*

http://birrell.org/andrew/papers/024-DatabasesPaper-SOSP.pdf

Based on that paper, you can write a small database engine. I suggest you to add a CLI tool,  a SQL parser and executor .. for example!

You could take a look at the SQLite code source to get ideas how this is implemented. By doing that, you get a better understanding how databases work.

If you did, please comment 🙂

Postgresql-Get the number of rows affected

You will find a way below to get the number of rows affected by an UPDATE or a DELETE statement.

 
CREATE FUNCTION update_foobar(id INT, field1 VARCHAR(40))
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
    -- some variables declarations
BEGIN
    -- UPDATE or DELETE
    -- then 
    GET DIAGNOSTICS ru := ROW_COUNT;
    RETURN ru;
END;
$$ ;

Setup sftp server on debian8 (chroot)

Let’s start by:

su -
groupadd sftp_users
usermod -G sftp_users my_username

Then:

emacs /etc/ssh/sshd_config
 
# Search the line below and replace it
Subsystem sftp /usr/lib/openssh/sftp-server
# by this one
Subsystem sftp internal-sftp
 
# Now each time that a user connects from the sftp group, 
# we are gonna apply theses rules:
 
Match Group sftp_users
 X11Forwarding no
 AllowTcpForwarding no
 ChrootDirectory /home
 ForceCommand internal-sftp

Finally:

systemctl restart ssh

https://serverfault.com/questions/660160/openssh-difference-between-internal-sftp-and-sftp-server

Edit: If you need to remove a user from a group:

gpasswd -d user group

or debian includes a tool:

deluser user group

https://unix.stackexchange.com/questions/29570/how-do-i-remove-a-user-from-a-group

SQL – From timestamptz A to timestamptz B

For PostgreSQL (tested on 9.4)

CREATE TABLE tests(id serial not null, created_on timestamptz);
INSERT INTO tests (created_on) VALUES (now());
2016-02-16 19:26:13.823126-05

I guess you have configured your timezone in your postgresql.conf file. I have for information ‘America/Toronto’.

SELECT created_on  AT TIME ZONE ‘Europe/Paris’ FROM tests;
2016-02-17 01:26:13.823126

shell – code de retour par une commande

Comment lire le code de retour d’une commande comme pwd ?

chaque commande executée vous renverra un code d’erreur situé entre 0 et 255. 0 pour opération réussie, sinon toute autre chiffre signifiera qu’une erreur s’est déroulée lors de l’exécution.

Le code de retour est disponible dans cette variable:

$?

Pour exemple

~ pwd toto
pwd: too many arguments
~ echo $?
~ 1

~ pwd
~ /home/user
~ echo $?
~ 0

Stay tuned