Thursday, 20 October 2016

Adding IP aliases in FreeBSD - Freebsd ifconfig add Remove Alias IPv4 / IPv6 / inet6

FreeBSD Assign IPv4 address
: # ifconfig em0 inet 192.168.10.5 netmask 255.255.255.0
FreeBSD ifconfig add alias for IPv4
: # ifconfig em0 inet 192.168.10.10/24 add
FreeBSD ifconfig remove alias for IPv4
: # ifconfig em0 inet 192.168.10.10/24 -alias
For IPv6
FreeBSD Enable IPv6 functionality of the interface:
: # ifconfig em0 inet6 -ifdisabled
FreeBSD Add the IPv6 address 2001:DB8:DBDB::123/48 to the interface em0:
: # ifconfig em0 inet6 2001:db8:bdbd::123 prefixlen 48 alias
FreeBSD ifconfig remove/delete Alias for IPv6 inet6
: # ifconfig em0 inet6 2001:db8:bdbd::123/48 delete

Monday, 22 August 2016

PostgreSQL setval Sequence - PostgreSQL manually alter sequence - Reset sequence of setval in PostgreSQL - Ali Raza Bhayani


In one of the my PostgreSQL tables, I used a very handy builtin Sequence Manipulation function setval() of PostgreSQL to generate Primary Keys in a sequential and controlled manner. But during a migration, I wanted to identify new records by Primary Key sequence greater than thousand. A very handy and tested recipe to restart the setval() function sequence for such cases is by using RESTART WITH in the following way:
ALTER SEQUENCE sequence_name RESTART WITH 1000;
is equivalent to:
    SELECT setval('sequence_name', 1000, FALSE);
Either of the statements may be used to restart the sequence and you can get the next value by:
    nextval('sequence_name')
The above recipe can also be used to reset PostgreSQL primary key sequence when it falls out of sync.

PostgreSQL setval Sequence - PostgreSQL manually alter sequence - Reset sequence of setval in PostgreSQL - Ali Raza Bhayani


In one of the my PostgreSQL tables, I used a very handy builtin Sequence Manipulation function setval() of PostgreSQL to generate Primary Keys in a sequential and controlled manner. But during a migration, I wanted to identify new records by Primary Key sequence greater than thousand. A very handy and tested recipe to restart the setval() function sequence for such cases is by using RESTART WITH in the following way:
ALTER SEQUENCE seq RESTART WITH 1000;
is equivalent to:
    SELECT setval('sequence_name', 1, FALSE);
Either of the above statements may be used to restart the sequence and for getting the next value following statement can be used:
    nextval('sequence_name')
The above recipe can also be used to reset PostgreSQL primary key sequence when it falls out of sync.

Wednesday, 29 June 2016

Install and run Redis on Mac OS - Redis Server Installation and First Run

Following is the recipe to install Redis server on Mac OS using homebrew in a very simple manner:

 $ brew install redis


After installation, you may edit Redis configuration file by going to the path via Mac OS terminal:

$ /usr/local/etc/redis.conf

To start Redis Server using configuration file on Mac OS, use following command:
$ redis-server /usr/local/etc/redis.conf

After running the Redis Server on Mac OS, you can check whether Redis Server is running by opening a new terminal window and enter following command:
$ redis-cli ping

Install and run Redis on Mac OS - Redis Server Installation and First Run

Following is the recipe to install Redis server on Mac OS using homebrew in a very simple manner:

 $ brew install redis


After installation, you may edit Redis configuration file by going to the path via Mac OS terminal:

$ /usr/local/etc/redis.conf

To start Redis Server using configuration file on Mac OS, use following command:
$ redis-server /usr/local/etc/redis.conf

After running the Redis Server on Mac OS, you can check whether Redis Server is running by opening a new terminal window and enter following command:
$ redis-cli ping

The server should reply PONG which means that the server is pinging.

Tuesday, 24 February 2015

MongoDB Correct way to start MongoDB - Error Cannot connect to mongodb errno:61 Connection refused [Solved]

Recently, while involved in full stack Django development and developing an application using Mongodb as database backend, I encountered following error after installing Mongodb on my mac. Ok first, I installed Mongodb by using brew install command:

brew update
brew install mongodb

After installing Mongodb, I tried to access the mongo shell by using mongo command, but I got "Cannot connect to mongodb errno:61 Connection refused error" . Here is the full trace:

alis-air:~ aliraza$ mongo
MongoDB shell version: 2.6.6
connecting to: test
2015-02-24T17:51:36.067+0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-02-24T17:51:36.069+0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

I searched for correct ways to start Mongodb on Mac OS. I tried several solutions but the one which worked for me is as follows: In the shell write sudo mongod to start it.

$ mkdir -p /data/db
$ sudo mongod

This started my Mongodb. Next I opened another shell instance (new shell window) and wrote mongo command and it worked without Error Cannot connect to mongodb errno:61 Connection refused! MongoDB starting Problem Solved.

$ mongo
MongoDB shell version: 2.6.6
connecting to: test
Server has startup warnings: 
2015-02-24T18:20:51.384+0500 [initandlisten] 
2015-02-24T18:20:51.384+0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> 

Friday, 30 January 2015

Django Setting DEBUG = False causes 500 Error - Django 500 error debug false - ALLOWED_HOSTS Problem [SOLVED]

Python Django alirazabhayani Full stack development
Django Debug False 500 error Solved
Being involved in Full Stack Django/Python Web Application Development for 3 years now, I recently deployed my Django application on a test server and encountered Server Error (500) on Django when template debug is set to False. That is in Django settings.py, when I changed DEBUG = FALSE from DEBUG = TRUE, it caused 500 error.

I had upgraded my application from Django 1.4 to Django 1.7. I came to know that 500 error on DEBUG = False error is encountered by everyone using django 1.5 or greater as soon as they change their settings.py to DEBUG = False. Well my problem got solved after reading several blogs and digging deeper in the Django Docs for DEBUG = False ALLOWED_HOSTS settings

What I did was, in settings.py, changed ALLOWED_HOSTS value in the following way:
ALLOWED_HOSTS = ['123.123.198.123']
# Above mentioned IP is not my actual IP. Enter your actual server IP or domain name here. 

If you have a domain name of your server, you may write:
ALLOWED_HOSTS = ['www.example.com']
You can also use a '*' wildcard to allow all hosts. But this is not recommended in the production environment.
ALLOWED_HOSTS = ['*']
You can find a full detail regarding the ALLOWED_HOSTS settings here hidden deep inside django document