parsed.org

Tips by tag: gotcha

Booleans In The WHERE Clause by xinu on May 03, 2005 05:21 PM

If you're going to use a boolean condition in your where clause, you're going to want to make sure you use an operator so that the index is used (if present).

For example, this will not use the index:

db=> SELECT id FROM users WHERE active;

This will use the index:

db=> SELECT id FROM users WHERE active = true;
expressionsgotchaindexperformancepostgresqlsql

Use the form ::type to ensure that a value is cast to the proper type:

SELECT * FROM table WHERE column = 5::bigint;

In this case, column is indexed and is a bigint. The index will not be used if the query planner doesn't encounter a value of the index type. Note: this only applies in PostgreSQL 7.x.

gotchaindexperformancepostgresqlsqlsyntaxtypes
Change Default Escape Binding by cygnus on Jan 13, 2005 08:59 AM

The default binding is typically C-a. I like to use C-j:

escape "^j^j"

I also like to use C-j l to get a window list instead of C-j ":

bind 'l' windowlist -b
bindbindingescapegotchakeystrokesscreenscreenrcwindowlist
Fixing Munged Template DB by xinu on Jan 12, 2005 10:24 AM

If you've munged your template1 database, you can rebuild it from the template0 database.

First, you must set the datistemplate attribute of template1 to false so we can drop it:

xinu=# UPDATE pg_database SET datistemplate = false WHERE datname = 'template1';
UPDATE 1
xinu=# DROP DATABASE template1;
DROP DATABASE

Next, re-create template1 using template0 as a template:

xinu=# CREATE DATABASE template1 WITH TEMPLATE = template0;
CREATE DATABASE

Then restore the datistemplate attribute of template1:

xinu=# UPDATE pg_database SET datistemplate = true WHERE datname = 'template1';
UPDATE 1
debugginggotchapostgresqlpsqlrecoveryrestoresqltemplate
Fixing the Backspace Key by cygnus on Nov 14, 2005 11:14 AM

On some systems (and for some terminal types), Emacs' use of the backspace key can be confusing. The backspace key may behave like the Delete key. You can fix this either by using this elisp in your ~/.emacs as follows:

(keyboard-translate ?\C-h ?\C-?)

This shell command may work if the elisp does not:

stty erase '^?'
backspacecrapdeletedot-emacseditorsemacsgotchakeystrokesterminal
Incorrect Checksum by xinu on Jan 12, 2005 10:22 AM

If you see the following when trying to load a newly transplanted database, it may be due to a difference in architecture (32-bit vs. 64-bit):

FATAL:  incorrect checksum in control file.

The moral is: never do a direct copy of the data directory. It isn't considered good practice.

64bitarchitecturedebugginggotchapostgresqlrecoveryrestore
MySQL DB & User Creation by xinu on Jan 12, 2005 10:50 AM

To create a new database:

$ mysqladmin create <database_name>

To grant permissions to a user, run this:

$ mysql -u root -p
Password: (enter password)
mysql> GRANT ALL ON db_name.* TO username@localhost IDENTIFIED BY "userpasswd";

To flush the privilege tables, run this:

$ mysqladmin flush-privileges

or:

mysql> flush privileges;

To revoke the privileges from a particular user/host pair:

mysql> revoke all privileges, grant option from username;
commandsgotchamysqlmysqladminpermissionsrevokesql
Optimize Firefox for Broadband by xinu on Jan 12, 2005 01:37 PM

Open about:config in a new tab and make the following changes:

network.http.pipelining -> True
network.http.pipelining.maxrequests -> 10

Anywhere on the screen, right-click and add a new integer:

nglayout.initialpaint.delay -> 0

If you're using a proxy, also change the proxy versions:

network.http.pipelining.proxy.pipelining -> True

WARNING: Be conservative when setting your pipelining settings. To the untrained eye this feature looks like a DOS attempt on the server side and might get you blocked.

browserconfigurationfirefoxgotchanetworkperformance
Reset Auto-Increment by xinu on Jan 15, 2005 06:09 PM

Deleting all the rows from the table will leave you adding rows where the last one left off. To bring it back to the beginning, run truncate tablename.

gotchamysqlsqltruncate
SCP Symlinks by xinu on Dec 19, 2005 12:05 PM

If you're running scp -r, beware of symlinks; they are followed rather than preserved. This might be favorable behavior if you're referencing files outside what you're copying, but if you're copying symlinks which reference other parts of what you're copying, the referenced files will be duplicated on the destination host.

Take, for example, the following files on host A:

~/myfiles/
  foo/
    a.txt
  bar/ -> foo/

When you run this command on host B:

joe@B:~$ scp -r joe@A:~/myfiles .

The result on host B will be:

~/myfiles/
  foo/
    a.txt
  bar/
    a.txt
commandsgotcharecursivescpshellsymlinks
Session ID Format by cygnus on Aug 12, 2005 03:19 PM

Beware that on some versions of PHP, the PHP session ID value is a hexadecimal hash but on some newer systems the configuration is used to adjust the contents of the session ID string:

; Define how many bits are stored in each character when converting
; the binary hash data to something readable.
;
; 4 bits: 0-9, a-f
; 5 bits: 0-9, a-v
; 6 bits: 0-9, a-z, A-Z, "-", ","
session.hash_bits_per_character = 5
configurationgotchahexadecimallanguagesphpphp.iniprogrammingsession
Unmounting a Frozen NFS Mount by cygnus on Feb 08, 2006 02:24 PM

If an NFS mount is frozen because the endpoint is unavailable, you can try a "lazy umount" on the mount to let the kernel take care of cleaning it up, rather than letting user-space processes wait on it:

# umount -l /path/to/mount

Additionally, you can use the NFS "soft" option when mounting the share to prevent hard locking of this kind; see nfs(5). Thanks to Kevin Turner for this tip.

brokenconfigurationfilesystemfrozengotchalazymountnfssoft
Using Your Own Template Database by cygnus on Jun 29, 2006 07:36 PM

If you have a database mytemplate that you'd like to use as a template, update its datistemplate attribute in the pg_database relation:

UPDATE pg_database SET datistemplate = 't' WHERE datname = 'mytemplate';

Then you can use it as a template when creating other databases:

CREATE DATABASE otherdb TEMPLATE mytemplate;
debugginggotchainternalspostgresqlrecoveryrestoresqltemplate
RSS