Thursday, 24 September 2015

Frequently Asked Firebird Interview Questions and Answers

31. How to select a random record from a table? 
There is no such feature in Firebird, but you can use some tricks. The following example requires that you have a unique integer column (primary key is usually used):
SELECT.. field_list...
FROM table t1
WHERE conditions
ORDER BY (t1 .int_col + seed)*4294967291 -((tl .int_col +
seed)*429496729 1/491 57)*491 57
If you just need one random record, limit the result set using FIRST or ROWS clause. This query will give consistent records for the same seed. If you wish to be completely random, you need to change the seed. You could use the value of int_col from previous run, or simply fetch a new value from a generator (just make sure the same value for seed is used in both places in expression).

32. How to specify transaction or query timeout? 
In order to keep the server low reasonable, you might want to limit the time a single query can consume. Firebird does not support this directly yet (there are plans for Firebird 3.0).
However, you could periodically query the monitoring tables (Firebird 2.1 and above) to detect and cancel long running queries. You can do:
Look for those having MON$STATE set to 1.
Please note that your database needs to be at least ODS 11.1, i.e. created with Firebird 2.1 or above. Older databases wont show you these tables even if you use Firebird 2.1 to access them. To learn more about ODS and how to retrieve it.

33. How to stop SuperServer service on Linux using only Firebird tools?
The server is started and stopped by ‘fbmgr’ executable from ‘bin’ directory of your
Firebird installation. It is called ‘ibmgr’ in Firebird 1.0. To start the serer type:
/opt/firebird/bin/fbmgr -start
To start the server with Guardian (Guardian watches the server and restarts it if it crashes) type:
/opt/firebird/bin/fbmgr -start -forever
To stop a running server, type:
/opt/firebird/bin/fbmgr -shut -user SYSDBA -pass ****
To force a shutdown, type:
/opt/firebird/bin/fbmgr -shut -force -user SYSDBA -pass ****
If you use Firebird 2 or higher, you can also use the regular ‘kill’ command to shutdown the server, as it handles the signals properly. Make sure you first kill the guardian and then the server (otherwise guardian would restart the server).

34. How to tell Firebird to only accept conections from XYZ host or network? 
This isn’t really a thing you should be configuring in Firebird. There is a
RemoteBind Address setting in firebird.conf which configures on which
interfaces/addresses the Firebird listens but that’s all. You should really use your system’s firewall to set this up.
Beside firewall, if you use Classic on Linux, you can use xinetd or meld access control files /etc/hosts.allow and /etc/hosts.deny. With xinetd you can also edit die xinetd configuration file for Firebird service, which is in /etc/xinetd.d/firebird and add a line like this:
“only _from”

35. How to use events with ZeBeDee, SSH or stunnel? 
You have to use SuperServer, set up RemoteAuxPort setting in firebird.conf and create two tunnels (one for data, other for events).

More Questions & Answers:-

No comments:

Post a Comment