Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backup info #48

Open
ducdongmg opened this issue Aug 9, 2024 · 2 comments
Open

backup info #48

ducdongmg opened this issue Aug 9, 2024 · 2 comments

Comments

@ducdongmg
Copy link
Owner

  1. Tạo file profile
  • Xem file profile đã có chưa
    $ cat $profile
  • Nếu chưa có thì tạo mới
    'C:\Users\nddong\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
  1. add command vào file
    function set-sshDat {ssh [email protected]}
    Set-Alias -Name ssh_dat -Value set-sshDat <--dòng này không cần cũng được

  2. Import file trên
    $ Import-Module $profile

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_aliases?view=powershell-7.4#alternate-names-for-commands-with-parameters

@ducdongmg
Copy link
Owner Author

  1. show ra danh sách các DB và oid (cái này là folder vật lý)
    psql -U postgres -p 5433 -c "SELECT * FROM pg_database;"

oid | datname
33063 | ffffff

  1. show danh sách các table vật lý tương ứng database
    /usr/local/pgsql/data/base/33063/

  2. table sẽ được quản lý trong pg_class
    trường hợp tìm oid của table
    select oid, relname from pg_class where relname ~ 'action_change';
    oid | relname
    33187 | action_change_log

  3. tìm xem table có đang có record nào đang bị lock hay không
    SELECT * FROM pg_locks where relation = 33187;

@ducdongmg
Copy link
Owner Author

Lock

  1. Tìm ID của table tương ứng trong bảng pg_locks

    SELECT * FROM pg_locks WHERE relation = 'action_change_log'

  2. Xem các record lock đang có trong table pg_locks

    SELECT pid, database, locktype, mode, granted, relation, fastpath, waitstart FROM pg_locks limit 10;

    hoặc xem lock của table có ID lấy từ step 1

    SELECT locktype, database, relation, virtualtransaction, pid, mode, granted FROM pg_locks where relation = 33187;

  3. Cách lock 1 record bằng câu select

    SELECT pg_advisory_lock(action_id, 12345), * FROM action_change_log WHERE action_id = 101279 limit 1;

  4. Hoặc lock 1 table

    SELECT pg_advisory_lock((SELECT cast(oid as integer) FROM pg_class WHERE relname = 'action_change_log'));

  5. Xem tất cả các thông tin liên quan đến lock

    select * from pg_locks join pg_stat_activity using (pid) where locktype='advisory';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant