Advertisement
kator

rsbd_lab_1

Oct 10th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. mkdir -p /var/lib/pgsql/rsbd2
  2. initdb /var/lib/pgsql/rsbd2
  3. pg_ctl -D /var/lib/pgsql/rsbd2 -l logfile start
  4. ---
  5. create server rsbd1 foreign data wrapper postgres_fdw options (host 'localhost', port '5432', dbname 'postgres');
  6. create user mapping for postgres server rsbd1 options (user 'postgres')
  7. import foreign schema public limit to (pracownicy) from server rsbd1 into public;
  8. ---
  9. select adres from zespoly where id_zesp=10;
  10. adres
  11. ------------
  12. PIOTROWO 1
  13. (1 row)
  14.  
  15. select placa_pod from pracownicy where id_prac=100;
  16. placa_pod
  17. -----------
  18. 999.00
  19. (1 row)
  20.  
  21. ===============
  22. =3==Transakcje=
  23. ===============
  24.  
  25. 1) -> terminal 1 odpowiedizalny za baze 1
  26. 2) -> terminal 2 odpowiedizalny za baze 2
  27. 3) -> terminal pomocniczy
  28. -------------------
  29.  
  30. 1) begin;
  31. 1) update pracownicy set placa_pod=777 where id_prac=100;
  32. 2) begin;
  33. 2) update zespoly set adres='PIOTROWO 88' where id_zesp=10;
  34. 1) PREPARE TRANSACTION 'distributed-transaction02-rsbd1';
  35. 2) PREPARE TRANSACTION 'distributed-transaction02-rsbd2';
  36. 3) pg_ctl -D /var/lib/pgsql/rsbd2 stop
  37. 3) pg_ctl -D /var/lib/pgsql/rsbd1 stop
  38.  
  39. 3) pg_ctl -D /var/lib/pgsql/rsbd1 start
  40. 3) pg_ctl -D /var/lib/pgsql/rsbd2 start
  41.  
  42. 1) select * from pg_prepared_xacts;
  43. transaction | gid | prepared | owner | database
  44. -------------+-------+-------------------------------+----------+----------
  45. 1778 | 02-01 | 2019-10-10 10:07:49.471017-04 | postgres | postgres
  46. (1 row)2) select * from pg_prepared_xacts;
  47. transaction | gid | prepared | owner | database
  48. -------------+-------+-------------------------------+----------+----------
  49. 1769 | 02-02 | 2019-10-10 10:07:59.102974-04 | postgres | postgres
  50. (1 row)
  51.  
  52. ==================
  53. =4==Zakleszczenie=
  54. ==================
  55.  
  56. 1) begin;
  57. 1) select placa_pod from pracownicy where id_prac=100 for update nowait;
  58. 1) update pracownicy set placa_pod=placa_pod+10 where id_prac=100;
  59. 2) begin;
  60. 2) select adres from zespoly where id_zesp=10 for update nowait;
  61. 2) update zespoly set adres='PIOTROWO 88' where id_zesp=10;
  62. 1) select adres from zespoly where id_zesp=10 for update nowait;
  63. 1) update zespoly set adres='PIOTROWO 77' where id_zesp=10;
  64. 2) select placa_pod from pracownicy where id_prac=100 for update nowait;
  65. 2) update pracownicy set placa_pod=placa_pod+10 where id_prac=100 for update nowait;
  66.  
  67. ============
  68. =5==Repliki=
  69. ============
  70.  
  71. 1) select * from zespoly_replika;
  72. wady ? po kazdej aktualizacji trzeba odsiwezyc zawartosc materializowanych perpspektyw
  73.  
  74. curl https://install.citusdata.com/community/rpm.sh | sudo bash
  75. sudo yum install -y pg_cron_11
  76.  
  77. 81,0-1 Bot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement