Showing posts with label Database. Show all posts

Backup Restore PostgreSQL in Windows

Backup database is saving your current database for archive that data to hard disk or storage.

For backup your data you can type this command in CMD (terminal for windows):

D:\Postgre8.3\bin\pg_dump.exe -h localhost -p 5432 -U postgres -F c -b -v -f "C:\Users\user\Desktop\CurrentDatabase.backup" poltek

Wait until finish.


Restore database is important step if you move database from old database to new database.

One of easy and fast step is using terminal and pg_restore tool for restore database. For restore your data you can type this command in CMD (terminal for windows):

D:\Postgre8.3\bin\pg_restore.exe -h localhost -p 5432 -U postgres -d poltek -v "C:\Users\user\Desktop\CurrentDatabase.backup"

and wait until process finish.

LOG: logger shutting down Error Postgresql (With Restart)

Login with postgres user
# su postgres

And then restart PostgreSQL
$ pg_ctl -D /usr/local/pgsql/data restart

Traceroute With Port Email

Sometime you must your internet provider for check what network support for email server:

# traceroute -n -T -p 25 gmail-smtp-in.l.google.com

BIND 9 Install / Named in Ubuntu


Bind is great DNS software. If you want to install follow this intruction:

  1. apt-get update
  2. apt-get upgrade
  3. apt-get install bind9
  4. /etc/init.d/apparmor teardown
  5. update-rc.d -f apparmor remove
  6. wget --user=ftp --password=ftp ftp://ftp.rs.internic.net/domain/db.cache -O /etc/bind/db.root
  7. Change/Add this line in /etc/bind/named.conf.option in option{}
    allow-query { any; };
    allow-recursion { any; };
    forwarders {
    8.8.8.8;

    8.8.4.4; 

    };
    dnssec-validation no;
  8. /etc/init.d/bind9 restart
  9. update-rc.d bind9 defaults

Done thank's

Nur Choliku Anwar

could not create semaphores: No space left on device (Shared Memory and Semaphores)

Pernah ketemu problem kaya gitu?

Postgresqlnya ga bisa hidup...nyebelin kan..

Trus Gimana?


  1. Kurangi nilai max_connections pada postgresql.conf
  2. Tambahkan nilai kernel.shmmax dan kernel.shmall pada /etc/sysctl.conf
  3. #sysctl -p
  4. service postgresql start
  5. FINISH

Change Password Postgresql

  1. Bypass login with setting /var/lib/pgsql/data/pg_hba.conf From "MD5" to "ident" (REMEMBER!: return back after finish), example:
    local all all ident
    host all all 127.0.0.1/32 ident
    host all all 0.0.0.0/0 md5
    host all all ::1/128 ident
  2. service postgresql restart
  3. su postgres
  4. psql
  5. ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
  6. \q
  7. exit
  8. service postgresql restart
Salam,

Nur Cholikul Anwar

Disable IPV6 Centos

# vim /etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

# sysctl -p

Device eth0 does not seem to be present, delaying initialization

For Solve that problem:

# echo "" > /etc/udev/rules.d/70-persistant-net.rules
# vim /etc/sysconfig/network-scripts/ifcfg-eth0 # reboot

HWADDR=YOUR_MAC_ADDRESS

Salam,

Nur Cholikul Anwar

Last ID in PostgreSQL using adodb


$sql="INSERT INTO pollquestion (question,pollID,dtcreated,dtmodified) values (".
tosql($txtquestion,"Text").", ".
tosql($pollid,"Number").", ".
"Now(),Now())";
$svdb=clone $db;
$svdb->query($sql.' RETURNING questionid');
$svdb->next_record();
$qid=$svdb->f("questionid");

and you can try:
$this->master_conn->PO_Insert_ID('announcement','modid');
=>> 'announcement': table name
=>> 'modid': an increment id

How To fix invalid byte sequence for encoding "UTF8"

To solve that: clear the spaces between the commas in sql query PHP or you can add/change to:
utf8_encode($variabel);

Salam,

[NCA]

Differences Postgresql Script and Mysql Script


This is Differences Postgresql Script and Mysql Script


mysql: SHOW DATABASES
postgresql: \l
postgresql: SELECT datname FROM pg_database;


mysql: SHOW TABLES
postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';


mysql: DESCRIBE TABLE
postgresql: \d+ table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';


mysql: SHOW COLUMNS
postgresql: \d table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';


Export Data MySQL kedalam file format CSV

mysqldump -u [username] -p -t -T/tmp [database] --fields-enclosed-by=\" --fields-terminated-by=,

If you have problem don't change /tmp directory :-)

and this is an output (example):

"1","Nur Cholikul","Anwar","2000-01-01 01:01:01"
"2","Putri","Yuniartis"," 2000-01-01 01:01:01 "
"3","Jaringan","Kantor"," 2000-01-01 01:01:01 "

Membuat Perbandingan atau rasio Terkecil antar 2 (dua) angka Excel

Misalkan:
Ada Dua buah angka yang berada di A1 dan B1 untuk hasilnya ditampikan pada C1
     |  A   |  B   |  C  |
 1  | 12  | 16 | 3:4 |

Maka rumus untuk C1 adalah:
=IF(OR(A1=0, B1=0),A1&":"&B1,(A1/GCD(A1,B1))&":"&(B1/GCD(A1,B1)))

GCD: digunakan untuk mencari FPB (Faktor Persekutuan Besar)


Suppose that:
There are Two numbers are in A1 and B1 to C1 results are displayed in

     |  A   |  B   |  C  |
 1  | 12  | 16 | 3:4 |


Then the formula for C1 is:
= IF (OR (A1 = 0, B1 = 0), A1 & ":" & B1, (A1/GCD (A1, B1)) & ":" & (B1/GCD (A1, B1)))

GCD: used to find gcd (a factor of the Great Guild)


Salam damai selalu,

NCA :-)

Chown with folder/file name

Example you have a folder or file name at /home

abdillah             fauzan            kjbi           rosmaniar
adbis                fehmeed           kji            sekretariat
admin                fikri             kmk            sekretariatpd1
admniaga             grafika           kopma          sekretariatpd2
agah                 gretha            ksa            sekretariatpd3
agung                hani              ksm            sekretariatpd4

and then you want that folder/file get owner same as folder/file name.

Try this:

  1. cd /home
  2. Type at terminal:
     for file in *; do
    chown  -R $file'.pnj' $file;
    done
  3. Finish :-)

Authentication With LDAP


   # setup
+--------[ Choose a Tool ]---------+
| |
| Authentication configuration |
| Firewall configuration |
| Keyboard configuration |
| Network configuration |
| System services |
| Timezone configuration |
| X configuration |
| |
| +----------+ +------+ |
| | Run Tool | | Quit | |
| +----------+ +------+ |
| |
| |
+----------------------------------+
Pilih : Authentication configuration
+----------------[ Authentication Configuration ]-----------------+
| |
| User Information Authentication |
| [ ] Cache Information [*] Use MD5 Passwords |
| [ ] Use Hesiod [*] Use Shadow Passwords |
| [*] Use LDAP [*] Use LDAP Authentication |
| [ ] Use NIS [ ] Use Kerberos |
| [ ] Use Winbind [ ] Use SMB Authentication |
| [ ] Use Winbind Authentication |
| [ ] Local authorization is sufficient |
| |
| +--------+ +------+ |
| | Cancel | | Next | |
| +--------+ +------+ |
| |
| |
+-----------------------------------------------------------------+
Choose "*" like example, and then click Next.
+-----------------[ LDAP Settings ]-----------------+
| |
| [ ] Use TLS |
| Server: ldap://127.0.0.1/_______________________ |
| Base DN: dc=jaringankantor,dc=com________________ |
| |
| +------+ +----+ |
| | Back | | Ok | |
| +------+ +----+ |
| |
| |
+---------------------------------------------------+
Input server with 127.0.0.1 and Base DN : dc=jaringankantor, dc=com

Setting Root Directory Http to Own Home Directory


  1. Disabled selinux:
    # vim /etc/selinux/config
    SELINUX=disabled
    ESC => :wq
  2. Restart your PC
  3. Config httpd.conf:
    # vim /etc/httpd/conf.d/welcome.conf
    and mark with #
    #<LocationMatch "^/+$">
    #    Options -Indexes
    #    ErrorDocument 403 /error/noindex.html
    #</LocationMatch>
    ESC => :wq
    # vim /etc/httpd/conf/httpd.conf
    User anwar
    Group anwar
    .
    .
    DocumentRoot "/home/anwar/public_html"
    .
    .
    <Directory "/home/anwar/public_html">
    ESC => :wq
  4. Restart httpd:
    # service httpd restart
  5. FINISH

How to backup MYSQL database

# mysqldump -u username -p database_name > dump.sql


and enter your password

Running OpenVPN as Daemon when start

Hello All,

Please type this command:
# vim /etc/rc.local

and go to end of line with type :$ and press i and then add this line (example):
openvpn --cd /etc/openvpn/ToRouterJakarta --daemon --config client.conf

press ESC and type :wq

FINISH...Alhamdulillah

Bagaimana Merefresh Parent Pada saat Popup di close?

Ketikan ini pada windows popupnya:

function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow) {
window.opener.progressWindow.close();
}
window.close();
}


dan Pada windows popup-nya

Select integer dengan input string pada PostgreSQL 9 supaya tidak error

Ada yang pernah ngalamin ga query seperti ini:

SELECT user_id, name where user_id LIKE '%ANWAR%' or name LIKE '%ANWAR%';


Catatan: user_id adalah tipe data Integer.

Pasti error deh :-)
Sekarang cobain deh membuat fungsi ini supaya bisa tetep running dengan query diatas:


CREATE FUNCTION int_to_text(INT4) RETURNS TEXT AS '
SELECT textin(int4out($1));
' LANGUAGE SQL STRICT IMMUTABLE;
CREATE CAST (INT4 AS TEXT)
WITH FUNCTION int_to_text(INT4)
AS IMPLICIT;


tadaa....sukses kan ^_^

Untuk Script dibawah ini agar bisa men-select semua tipe data dengan string:

CREATE FUNCTION pg_catalog.text(integer) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int4out($1));';

CREATE CAST (integer AS text) WITH FUNCTION pg_catalog.text(integer) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(smallint) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int2out($1));';

CREATE CAST (smallint AS text) WITH FUNCTION pg_catalog.text(smallint) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(oid) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(oidout($1));';

CREATE CAST (oid AS text) WITH FUNCTION pg_catalog.text(oid) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(date) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(date_out($1));';

CREATE CAST (date AS text) WITH FUNCTION pg_catalog.text(date) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(double precision) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(float8out($1));';

CREATE CAST (double precision AS text) WITH FUNCTION pg_catalog.text(double precision) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(real) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(float4out($1));';

CREATE CAST (real AS text) WITH FUNCTION pg_catalog.text(real) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(time with time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(timetz_out($1));';

CREATE CAST (time with time zone AS text) WITH FUNCTION pg_catalog.text(time with time zone) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(time without time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(time_out($1));';

CREATE CAST (time without time zone AS text) WITH FUNCTION pg_catalog.text(time without time zone) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(timestamp with time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(timestamptz_out($1));';

CREATE CAST (timestamp with time zone AS text) WITH FUNCTION pg_catalog.text(timestamp with time zone) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(interval) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(interval_out($1));';

CREATE CAST (interval AS text) WITH FUNCTION pg_catalog.text(interval) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(bigint) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(int8out($1));';

CREATE CAST (bigint AS text) WITH FUNCTION pg_catalog.text(bigint) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(numeric) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(numeric_out($1));';

CREATE CAST (numeric AS text) WITH FUNCTION pg_catalog.text(numeric) AS IMPLICIT;

CREATE FUNCTION pg_catalog.text(timestamp without time zone) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT textin(timestamp_out($1));';

CREATE CAST (timestamp without time zone AS text) WITH FUNCTION pg_catalog.text(timestamp without time zone) AS IMPLICIT;